2015-02-09 56 views
0

我已經編譯了一個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>

+1

您是否嘗試過使用Chrome開發者工具? – Dbz 2015-02-09 21:52:22

+0

Stackoverflow用於編碼問題。你所謂的問題沒有代碼。所以,當你被拒絕投票並關閉時,不要感到驚訝 – 2015-02-09 22:00:45

+0

'option'標籤上的'onclick'事件並不適用於所有瀏覽器。你需要將一個點擊處理程序綁定到周圍的'select'元素。見[這個問題](http://stackoverflow.com/questions/1402227/click-event-on-select-option-element-in-chrome)。 – 2015-02-09 22:28:06

回答

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>

相關問題