/    Sign up×
Community /Pin to ProfileBookmark

Close the window if user does exit it

I have one html page, I replace it using Javascript to another, after checking if client browser is IE 6+ or not.

I emphasize that everything seems to be okay with browser check part.

I have the html page, [B]first.hml[/B]:

[CODE]<HTML>
<HEAD>
<TITLE>MyFirstPage</TITLE>
</HEAD>
<script LANGUAGE=”Javascript”>
if(window.navigator.appName == “Microsoft Internet Explorer” && window.navigator.appVersion.substring(window.navigator.appVersion.indexOf(“MSIE”) + 5, window.navigator.appVersion.indexOf(“MSIE”) + 8) >= 6)
window.location.replace(“/second.html”)
else
window.location=”/index_no_IE.html”
</script>
<BODY>
</BODY>
</HTML>[/CODE]

If client uses IE 6+ he will get the [B]second.html[/B], not in new window, but in the same window, first.html will be replaced by second.html:

[CODE]<HTML>
<HEAD>
<TITLE>MySecondPage</TITLE>
</HEAD>
<body onblur=”self.close()”>
<B>
This is The Second Page!
</B>
</BODY>
</HTML>[/CODE]

In this second page is the content user has to submit, he/she must not leave the page before that. I mean leave – go to another window, application, cut content, go back to this second page, paste. He/she must not switch between windows and applications.

I want the page to be closed if user goes to another window, or any other application, if user does switch to anything else.

Because of that, I did insert <body onblur=”self.close()”> into the second.html

But I got the question:

[QUOTE]

[B]The Web page you are viewing is trying to close the window.
Do you want to close this window?[/B]

[/QUOTE]

Is there any possibility to avoid the question? To close the window without the question I mentioned above? What should I add to the second page?

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@KorOct 14.2005 — Nope. AFAIK there is no way to avoid that message alert.
Copy linkTweet thisAlerts:
@computerforceauthorOct 14.2005 — There should be some way, I am trying to force the second page - same window to be the one which will be able to decide for itself to be closed.

I think I am close to the solution.
Copy linkTweet thisAlerts:
@KorOct 14.2005 — Whenever you will try to close a main page (NOT a popup) using a javascript method, you will receive that message (in IE) and even you will be ignored in this atempt (in Firefox)
Copy linkTweet thisAlerts:
@computerforceauthorOct 14.2005 — If you go thru the scripts, you would see that first page became the second in the same window. Means, the second page is not new popup page in a new window. This would give possibility to solve the problem.
Copy linkTweet thisAlerts:
@KorOct 14.2005 — Not really, as [B]location[/B] methods will not create a javascript relationship between pages. Only window.open(url,newtarget) will open a new page which may be closed without alert message.
Copy linkTweet thisAlerts:
@felgallOct 14.2005 — Also your code isn't testing for IE6 specifically, it is just testing if the browser claims to be IE6 and other browsers can make that claim. Opera in particular is often set to identify itself as IE so that crappy scripts that test for a specific browser instead of testing for feature support will allow it to participate.
Copy linkTweet thisAlerts:
@computerforceauthorOct 14.2005 — First: I think I have solution for the problem.

By using three parts:

this.focus()

self.opener=this

self.close()

After this I got no dialog box question!

Next, I agree that the IE detect is not perfect one.

Do you have the solution based on difference in features between IE and Opera?
×

Success!

Help @computerforce 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.17,
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,
)...