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

时间:2015-02-09 21:45:45

标签: javascript validation google-chrome iframe

我使用来自其他代码块和一些逆向工程的片段编译了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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

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

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>