Skip to content

Add force refresh (alt version) #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions jquery.popupwindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
status: false,
toolbar: false,
top: 0,
width: 500
width: 500,
forcerefresh:true
};

$.popupWindow = function(url, opts) {
Expand All @@ -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') {
Expand Down