簡體   English   中英

在IE中,window.opener.location為null。 在Chrome中正常運行。

[英]window.opener.location is null in IE. Works fine in Chrome.

 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運行時錯誤消息,提示位置為null,這似乎與開啟程序有關。

IE中的等效項是什么?

嘗試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>");

您永遠不要使用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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM