2009-08-04 38 views
0

我的項目是在Firefox,谷歌chorme和IE 8.0在IE 6.0和7.0(window.location)中運行我的項目時出現問題?

完美運行,但它不工作在IE 6.0或7.0

我意識到這是在window.location的 給定的問題,我把我的代碼在這裏展示我在做什麼。

function GetEmailId() 
{ 
    var url="http://server.com/GetPostEmail.php"; 
    url=url+"&sid="+Math.random(); 
    xmlhttp.onreadystatechange=statechangedLogin2; 
    xmlhttp.open("GET", url, true); 
    xmlhttp.send(null); 
} 
function statechangedLogin2() 
{ 
    if(xmlhttp.readyState==4) 
    { 
     if(xmlhttp.responseText=="Login again") 
     { 
      window.location="http://server.com/profile.html"; 
     } 
    } 
} 

所以這個代碼在其他瀏覽器,除了IE 6和7 工作正常,當我從我的AJAX響應中xmlhttp.responseText應該去到profile.html而在IE 6和7它停留在原來的頁面上,我以前是qotw.html。

我認爲window.location有問題,可能我需要一個不同的命令。

另外我的GetXmlHttpObject看起來像這樣。

function GetXmlHttpObject() { 
    //var xmlHttp = null; 
    try { 
    xmlHttp = new XMLHttpRequest(); 
    } catch (e) { 
    try { 
     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 
    } catch (e) { 
     xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    } 
    return xmlHttp; 
} 

請如果有人可以幫我解決我的這個問題。

問候 zeeshan

注:我再次嘗試解碼我​​的代碼,並意識到在IE 6和7我的代碼永遠不會進入statechangedLogin2()。這就是我的代碼無法工作的原因。但爲什麼會發生這種情況,即使在IE8中,代碼在其他瀏覽器中也能正常工作?

+0

window.location應該工作。您是否調試過IE6或7中的代碼以確保window.location是問題(即將警告框放置在window.location行的上方)?代碼是否在最後一個「if」聲明中進入? – JamesEggers 2009-08-04 13:23:50

回答

1

location屬性是一個對象,url是該對象中的href屬性。改爲:

window.location.href="http://server.com/profile.html";