codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  OnUnLoad question.  chillywylly at 05:51 on Sunday, June 05, 2005
 

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!

  Re: OnUnLoad question.  Troy Wolf at 20:31 on Sunday, June 05, 2005
 

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>
Troy Wolf: site expert
SnippetEdit Website Editor


  Re: OnUnLoad question.  Troy Wolf at 20:31 on Sunday, June 05, 2005
 

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.
Troy Wolf: site expert
SnippetEdit Website Editor


  Re: OnUnLoad question.  chillywylly at 03:38 on Monday, June 06, 2005
 

Great!! Troy Wolf

Thanks! for your help....

  Re: OnUnLoad question.  hbou at 10:02 on Friday, June 24, 2005
 

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>

  Re: OnUnLoad question.  Julie at 21:48 on Friday, June 24, 2005
 

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?

  Re: OnUnLoad question.  hbou at 10:11 on Saturday, June 25, 2005
 

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



  Re: OnUnLoad question.  Julie at 00:48 on Sunday, June 26, 2005
 

Thank you for the response - I'll give that a try.

  Re: OnUnLoad question.  chillywylly at 00:43 on Sunday, July 03, 2005
 

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

  Re: OnUnLoad question.  Troy Wolf at 03:48 on Sunday, July 03, 2005
 

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.
Troy Wolf: site expert
SnippetEdit Website Editor









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
• Re: store string from text file to vector
• Re: c# .net Exception of type System.StackOverflowException was thrown.
• Re: error: expression must have a constant value
• Re: Script Does Folder Exist – If Not Create It
• $_GET not working
• GET METHOD
• Re: windows service - web service - com
• Re: Storing data from HTML to Excel or TXT
• Re: Help totalReads=1 totalReads++=2 write totalReads 3 not 2


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010