window.opener.location在IE中为null。适用于Chrome。

时间:2011-11-10 16:19:40

标签: javascript asp.net

 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中的等价物是什么?

2 个答案:

答案 0 :(得分: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>");

答案 1 :(得分: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);