windows .opener.location在IE中为空.在Chrome中工作良好

window.opener.location is null in IE. Works fine in Chrome.

本文关键字:Chrome 工作 opener IE windows location      更新时间:2023-09-26
 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运行时错误,说位置是空的,似乎它与打开器有关。

在IE中等效的是什么?

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

试试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>");