From c93c603239e345c5fd71cdd4ccc6137302af8a3a Mon Sep 17 00:00:00 2001 From: Todd Horst Date: Mon, 21 Apr 2014 09:31:39 -0400 Subject: [PATCH] Added force refresh (alt version) This is a slimmer implementation which doesn't keep a global list of open window handles. --- jquery.popupwindow.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/jquery.popupwindow.js b/jquery.popupwindow.js index 79ed5a6..b69e936 100644 --- a/jquery.popupwindow.js +++ b/jquery.popupwindow.js @@ -18,7 +18,8 @@ status: false, toolbar: false, top: 0, - width: 500 + width: 500, + forcerefresh:true }; $.popupWindow = function(url, opts) { @@ -45,10 +46,24 @@ params.push('left=' + options.left); params.push('top=' + options.top); - // open window + // define name var random = new Date().getTime(); var name = options.name || (options.createNew ? 'popup_window_' + random : 'popup_window'); - var win = window.open(url, name, params.join(',')); + + // try regaining access to a window handle, will fail for different origin + var winHref; + var win = window.open("", name, params.join(',')); + try { winHref = win.location.href; } catch (e) { } + + // determine whether to open window + // the user wants to always refresh, the href is a new page + // winHref could be 3 possible values + // 1. undefined - this failed grabbing url, meaning it exists, but on different origin - dont reload url + // 2. some url - this passed the assignment above, must be same origin - dont reload url + // 3. about:blank - the window didnt exist and the user now has a blank window - reload url + if (options.forcerefresh || winHref === "about:blank") { + win = window.open(url, name, params.join(',')); + } // unload handler if (options.onUnload && typeof options.onUnload === 'function') {