简体   繁体   中英

Javascript/JQuery: focus the popup window if already opened but not to reload it

Have the following code to open and focus the window popup, unless it hasn't opened yet. It works fine,

But the problem is after focus to the previous opened popup window, can't prevent reloading it and it makes loss of the data on it.

So how can prevent the existing window not to reload to retain the existing data when the link is clicked again?

window.open(url,"searchPatron","height=600,width=1000, status=yes,toolbar=no,menubar=no,location=no").focus();

Maybe it fits your needs:

DEMO

window['windows'] = {};
var url = "//testit.com";
$('button').click(function () {
    var popup =  window['windows'][url]? window['windows'][url]:
    window['windows'][url] = window.open(url, "searchPatron", "height=600,width=1000, status=yes,toolbar=no,menubar=no,location=no");
    popup.focus();
});

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