/    Sign up×
Community /Pin to ProfileBookmark

window.close() question:

Using the command:

<body onLoad=” window.close()”>

will result in a response warning the user that “the web page you are viewing is trying to close the window”.

How can you alter it, so that when the user relies NO, it will not close the window, but will re-direct the user to a different ULR.

Anyone? Thanks for any suggestions!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisDec 11.2003 — Browsers have built-in security that will not let you close a window that you did not open using JavaScript.

You cannot alter the action.

You can tell that the user said "no" by the fact that the page is still active. If you want to redirect to a different URL, just do that. IMHO, there isn't any valid reason to close the window if you did not open it.
Copy linkTweet thisAlerts:
@AunecahDec 11.2003 — How about adding a function instead of using the window.close()? Ask the user for confirmation - something like

if(confirm("The window you're browsing is trying to close itself. Go ahead with the action?"))

window.close();

else

window.location.href=[the location goes here];

Aunecah
Copy linkTweet thisAlerts:
@sydmilauthorDec 11.2003 — Aunecah, Gil, thanks for your replies!

What I'm trying to achieve is, when a user enters a certain page it will automatically attempt to close that page for him, but I'm giving him an option of not closing by redirecting him to another URL. As it is, answering NO to the window.close() prompt will leave him at the same URL where he entered, which I don't want.
×

Success!

Help @sydmil spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...