Current location: Hot Scripts Forums » General Web Coding » JavaScript » Popup Window Issue.


Popup Window Issue.

Reply
  #1 (permalink)  
Old 06-28-08, 08:50 AM
umarrana umarrana is offline
Newbie Coder
 
Join Date: Dec 2006
Location: Pakistan
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Popup Window Issue.

Hello there,

I am having problem and need suggestion, I want to popup a window (Opinion Box) when someone leaves my site. The following are the two scenarios in which I want to popup the opinion window:-

1. When user close the browser
2. When user leaves the site, by typing new URL other then my domain.

I have used <body onunload="getClose();">, <body onbeforeunload="getClose();">

This displays the popup window, but it keep displaying the window even when user navigate into my site (which is not required).

I have also used "document.referrer" and "document.location.href" to match the referring and current URLs. It neither work as well.

Please suggest any solution to this.

Thanks,
Umar
Reply With Quote
  #2 (permalink)  
Old 06-29-08, 06:03 AM
Vicious's Avatar
Vicious Vicious is offline
Community VIP
 
Join Date: Jan 2007
Location: Belgium
Posts: 584
Thanks: 0
Thanked 0 Times in 0 Posts
onunload is when the user goes off the page. Either the user then goes to another page of yours, or to another page on the internet. I think it is not possible to detect the difference.
__________________
Jack Bauer makes Chuck Norris cry
Reply With Quote
  #3 (permalink)  
Old 06-29-08, 06:35 AM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Vicious is correct, you cannot detect where the user goes, as that would be a security/privacy issue. But, you could make every internal link on your page execute a small script which disables the popup, simply by setting a bool.
Something like this:
JavaScript Code:
  1. var doPopup=true;
  2. function noPop()
  3. {
  4.  doPopup=false;
  5. }
  6.  
  7. function getClose()
  8. {
  9.   if(doPopup)
  10.  {
  11.     // Show the popup
  12.   }
  13.  return true;
  14. }
  15.  
  16. document.onload=function()
  17. {
  18.  var lnks=document.getElementsByTagName("a");
  19.  for(var i=0;i<lnks.length;i++)
  20.  {
  21.    if(lnks[i].href)
  22.    {
  23.      lnks[i].onclick=noPop;
  24.    }
  25.  }
  26. }
This should keep the popup from appearing when you navigate within your site. The bool is automatically set back to true when the page loads one of your internal sites, but if the browser doesn't follow the link (due to some script perhaps) you'll have to reset the bool yourself.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
creating a popup window? chrisrobertson JavaScript 1 08-18-06 11:37 AM
Replace Popup Window? aDcOoL Script Requests 2 03-04-06 04:48 PM
how do I update form, and hidden values in a form from a popup window? lordmerlin JavaScript 2 12-13-05 02:05 PM
Popup window (Novice) dgrover JavaScript 0 10-21-05 05:48 PM
php popup window code help, pls! usmaster81 PHP 5 04-29-05 04:09 PM


All times are GMT -5. The time now is 11:39 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.