2011-11-10 15 views
1
Response.Write("<script language='javascript'>alert(window.opener.location.pathname); if(window.opener.location.pathname.toString() == \"/page.aspx\"){window.opener.document.forms[0].submit();}</script>"); 

這適用於Chrome,但在IE瀏覽器中,我得到一個大量的javascript運行時錯誤,說位置爲空,似乎它與opener有點類似。IE中的window.opener.location爲空。在Chrome中運行良好。

什麼是在IE中的等效?

+0

退房http://stackoverflow.com/questions/990331/javascript-popup-issue-in-internet-explorer – Nerdtron

回答

0

你不應該使用Response.Write添加JavaScript頁面。查看頁面源代碼,您將看到腳本添加在頁面上的任何HTML標記之前。那很不好。您可以使用RegisterStartUpScript

ClientScriptManager cs = Page.ClientScript; 
Type cstype = this.GetType(); 
String cstext1 = "alert(window.opener.location.pathname);"; 
cs.RegisterStartupScript(cstype, "alert", cstext1, true); 
0

嘗試window.opener.document.location

Response.Write("<script language='javascript'>alert(window.opener.document.location.pathname); if(window.opener.document.location.pathname.toString() == \"/page.aspx\"){window.opener.document.forms[0].submit();}</script>"); 
+0

仍然會產生在IE :( – JustAnotherDeveloper

+0

同樣的錯誤是什麼錯誤? –

+0

現在林使用這個IE瀏覽器,並得到這個:'無法獲取propery的值「文檔」對象爲空或未定義 – JustAnotherDeveloper

相關問題