是否有特定于浏览器的代码验证器?

Is there a browser-specific code validator?

我使用其他代码块的片段和一些逆向工程编译了一个 JS 函数。它在 Firefox 中完全符合我的要求,但在 Chrome 中完全没有任何作用。我对它进行了检查和验证,它恢复正常,比如进行一些格式化。

是否有允许通过模拟浏览器进行选择性验证的工具?

罪魁祸首 - 下拉 iframe 更改器:http://injurypreventioncentre.ca/stories

js:

var xmlhttp;

function loadXMLDoc(url, cfunc) {
  if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
  } else { // code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange = cfunc;
  xmlhttp.open("GET", url, true);
  xmlhttp.send();
}

function story() {
  "use strict";
  loadXMLDoc("shareyourstory/story.txt", function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
    }
  });
}

function January() {
  "use strict";
  loadXMLDoc("shareyourstory/january.txt", function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
    }
  });
}

每个月都是一个函数。

HTML 调用它:

<select>
  <option value="Please select month" onclick="story()" selected>Please select month</option>
  <option value="January" onclick="January()">January</option>
</select>

经过多次修改,我有了工作代码。

var loadedobjects = ""
var rootdomain = "http://" + window.location.hostname

function dynamicText(url, containerid) {
  var page_request = false
  if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
  else if (window.ActiveXObject) { // if IE
    try {
      page_request = new ActiveXObject("Msxml2.XMLHTTP")
    } catch (e) {
      try {
        page_request = new ActiveXObject("Microsoft.XMLHTTP")
      } catch (e) {}
    }
  } else
    return false
  page_request.onreadystatechange = function() {
    loadpage(page_request, containerid)
  }
  page_request.open('GET', url, true)
  page_request.send(null)
}

function loadpage(page_request, containerid) {
  if (page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1))
    document.getElementById(containerid).innerHTML = page_request.responseText
}

function loadobjs() {
  if (!document.getElementById)
    return
  for (i = 0; i < arguments.length; i++) {
    var file = arguments[i]
    var fileref = ""
    if (loadedobjects.indexOf(file) == -1) {
      if (file.indexOf(".js") != -1) {
        fileref = document.createElement('script')
        fileref.setAttribute("type", "text/javascript");
        fileref.setAttribute("src", file);
      }

    }
    if (fileref != "") {
      document.getElementsByTagName("head").item(0).appendChild(fileref)
      loadedobjects += file + " "
    }
  }
}


function doChange(selectobjID, loadarea) {
  var selectobj = document.getElementById ? document.getElementById(selectobjID) : ""
  if (selectobj != "" && selectobj.options[selectobj.selectedIndex].value != "")
    dynamicText(selectobj.options[selectobj.selectedIndex].value, loadarea)
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<form>

  <select id="DynOptions" size="1" onChange="doChange('DynOptions', 'DynDiv')">
    <option value="">Please select month</option>
    <option value="directory/option1.txt">Option 1</option>
    <option value="option2.txt">Option 2</option>
  </select>

</form>

<div id="DynDiv">Landing page text changes.</div>