|
|
Hello Dear Xperts!
I am using the Onunload event to load a popup when the user close de main page(x button), my question is how "block" this action when a user clicks a hyperlink in the same page, i don't need to show the popup when this occurs..
your help is great appreciated!
|
|
|
|
So the user can exit the current page either by closing the browser or navigating away. They either navigate away using one of the hyperlinks you provide in your page, or they click a link external to your page -- such as on of their favorites, etc.
As I understand, you do not want to annoy the user with a popup if they navigate away using one of your hyperlinks. To accomplish this, you'll need to use javascript to do your navigation rather than directly link.
<script language="javascript">
function UnloadTrigger(stopPop) {
if (!stopPop) {
alert("This is where I'd pop a window.");
}
window.onunload = UnloadTrigger;
</script>
|
|
|
|
|
|
|
|
So the user can exit the current page either by closing the browser or navigating away. They either navigate away using one of the hyperlinks you provide in your page, or they click a link external to your page -- such as on of their favorites, etc.
As I understand, you do not want to annoy the user with a popup if they navigate away using one of your hyperlinks. To accomplish this, you'll need to use javascript to do your navigation rather than directly link.
<script language="javascript">
function UnloadTrigger(stopPop) {
if (!stopPop) {
alert("This is where I'd pop a window.");
}
window.onunload = UnloadTrigger;
</script>
|
|
<Added>
oops...I hit tab and enter and ended up accidentally submitting before I was done...doh!
<script language="javascript">
var unloadPop = true;
function Nav() {
unloadPop = false;
window.navigate(arguments[0]);
}
function UnloadTrigger() {
if (unloadPop) {
alert("This is where I'd pop a window.");
}
}
window.onunload = UnloadTrigger;
</script>
<body>
Instead of this:
<a href="http://www.snippetedit.com">SnippetEdit Website Editor</a>
<br /><br />
Do this:
<a href="javascript:Nav('http://www.snippetedit.com')">SnippetEdit Website Editor</a>
</body>
|
|
This way, when the user clicks a link, the javascript will set the unloadPop switch to false so when the UnloadTrigger fires, it will not pop the window.
|
|
|
|
|
|
Great!! Troy Wolf
Thanks! for your help....
|
|
|
|
Hi,
another nice way if you don't want to use custom coding is to use a frameset binded to the onunload event handler. The frameset will contain your page as a frame so the navigation within it will be separated from the actions on the browser linked to the main framset.
Your main page should look like this:
<frameset onunload="yourhandler()">
<frame name="FRAMENAME" src="PAGELINK">
</frameset>
|
|
|
|
This is soooo close to something I'm trying to do... I'm working with a department that provides online training, and I need to trigger a popup window (rather than an alert) if the user closes the browser using the X button. However, as long as they are moving around within the course content (clicking on links within the page), I don't want the popup to be triggered. Is it possible to do this?
|
|
|
|
Yes Julie you can do it.
Just develop your whole web site with regular links and once you're done, put its entry point in a frame within a frameset as I said in my previous reply. Then assign a handler in the window that contains the frameset for the onunload event.
Try smthing like this:
<html>
<SCRIPT FOR=window EVENT=onunload ATOMICSELECTION=true>
<!-- Put your script here -->
</SCRIPT>
<frameset>
<frame name="GiveAName" src="YourEntryPoint.html">
</frameset>
</html>
Regards,
Houcine Bourquouquou
|
|
|
|
Thank you for the response - I'll give that a try.
|
|
|
|
Troy...
Your help is great appreciated.
only a question more:
why the animated gif located in the main page(default.htm) are freezed when the popup is loaded?
Thanks Again
Att
ChillyWylly
|
|
|
|
|
I don't have a definitive answer, but seems to me that animated gifs in browser windows typically stop animating when their window loses focus, which would explain what you see. Why is that? I don't know...by design I guess.
|
|
|
|
|