Windows.open()JavaScript无法在IE

时间:2017-06-14 13:13:04

标签: javascript asp.net internet-explorer

我正在尝试使用以下代码打开新窗口。它在google chrome和firefox中正常工作,但在IE中它正在合并windows。 如果我通过user1登录,那么一个新窗口会打开,但是当我使用user2登录时,它不会打开新窗口,而是用user2替换user1的用户会话。

这是我的代码

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "name", "var myWindow =  window.open('" & pageurl & "','name','titlebar=yes,toolbar=no,directories=no,location=no,status=yes,overflow=hidden;menubar=no,resizable=yes,scrollbars=no,left=0,top=0,width=(screen.availWidth),height= (screen.availHeight)');   myWindow.resizeTo(screen.availWidth, screen.availHeight); ; myWindow.focus(); ", True)

每当新用户登录系统时,我想在IE中打开新窗口。

2 个答案:

答案 0 :(得分:0)

原因可能是您的pageurl变量不正确或包含空格。 (顺便说一下,你不知道从哪里得到它,所以你可能想把它改成window.location.href)。

另外,请尝试使用ClientScript.RegisterStartupScript

Page.ClientScript.RegisterStartupScript(GetType(), "name", "(js code)", true);

当您使用RegisterStartupScript时,它会在页面中的所有元素之后(在表单的结束标记之前)呈现您的脚本。这使得脚本可以调用或引用页面元素,而不会在页面的DOM中找不到它们。

另一方面,当您使用RegisterClientScriptBlock时,脚本会在Viewstate标记之后呈现,但之前呈现任何网页元素。

答案 1 :(得分:0)

window.open中的第二个参数是窗口名称/ ID。如果你保留相同的名称,当你命名那个窗口'name'时,窗口将被重用。我建议你使用_blank

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "name", "var myWindow =  window.open('" & pageurl & "','_blank','titlebar=yes,toolbar=no,directories=no,location=no,status=yes,overflow=hidden;menubar=no,resizable=yes,scrollbars=no,left=0,top=0,width=(screen.availWidth),height= (screen.availHeight)');   myWindow.resizeTo(screen.availWidth, screen.availHeight); ; myWindow.focus(); ", True)

参考:https://www.w3schools.com/jsref/met_win_open.asp