简体   繁体   中英

Focus on new window open by window.open

I want to open a new window by window.open and also focus that window even if the tab create new window is not selected.

As per my R & D If tab that is not selected and create window by some timer function, then opened window is not display on screen, it just display as blinking on taskbar.

Code:

win = window.open("",'_blank','titlebar=no, location=no, directories=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no, height=50, width=650');
var errorMessage= "Your session will expire in 1 minute,To extend your session, Please press the Extend button.";
win.document.write("<html><head><title>Session Expire</title></head><body><div style='color:red; line-height:50px;' id='message'>"+ errorMessage +"<input type='button' id='btn' value='Extend' /></div></body></html>");
win.focus();

I want open new window on center of the screen and the tab which create is not selected, and display new window even if I am currently working on other application

In short, don't do this.

My main web browsing is done on an iPad, iPhone or Android tablet. I don't have windows.

On my Mac, I run Chrome Full Screen. A new window doesn't make sense here either.

There is a reason that you can't focus it easily - it's annoying!

Rather than this, either use a modal dialog using JS, or have a bar animate in at the top or bottom using fixed position to get someones attention in a more friendly and usable way.

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