简体   繁体   中英

Windows.open() JavaScript not working in IE

I am trying to open new window using below code. Its working properly in google chrome and firefox but in IE its doing merging of windows. If i logged in through user1 then one new window gets open but when i login with user2 then instead of opening new window it replaces user session of user1 with user2.

Here's my code

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)

I want to open new window in IE everytime when new user logged in to system.

The reason could be your pageurl variable is incorrect or contains spaces. (By the way, it's not clear where you got it from, so you might want to change it to window.location.href ).

Also, try using ClientScript.RegisterStartupScript instead:

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

When you use RegisterStartupScript , it will render your script after all the elements in the page (right before the form's end tag). This enables the script to call or reference page elements without the possibility of it not finding them in the Page's DOM.

On the other hand, when you use RegisterClientScriptBlock , the script is rendered right after the Viewstate tag, but before any of the page elements.

The second parameter in window.open is the window name/id. if you leave the same name, As you are naming that window 'name' , the window is going to be reused. I recommend you to use _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)

Reference: https://www.w3schools.com/jsref/met_win_open.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM