Solved

popup window unpon exit of domain only

Posted on 2003-10-29
15
665 Views
Last Modified: 2011-04-14
I need code that make a window popup upon exit of a domain only, not on unload of any one page.

P.S. To who ever answers this question there will be an extra 1000 points and on top of that there will be an extra 500 points for anwsering within the next two hours.  Also I need a working example.

Thanks.
0
Comment
Question by:CFDevHead
  • 5
  • 5
  • 4
  • +1
15 Comments
 
LVL 8

Expert Comment

by:fozylet
ID: 9646898
0
 
LVL 7

Expert Comment

by:Xxavier
ID: 9646909
Try this

<html>
<head>

<script language="javascript">
<!-- hide this script from non-javascript-enabled browsers
/*
DESCRPTION: Display popup window, either fullscreen or normal popup of a specified dimension, along
with writing a cookie for each session to make sure ads are only displayed once.  By default this script
is configured to do a normal popup using the onExitFrames(); function so that the popup is only shown
after the user has left your domain.

*/
// setup variables
var address = "'http://www.js-x.com'";//popup url
var contentframe = "http://www.yahoo.com";//used with onExitFrames();
var fs=false;// fullscreen true/false
var w=640;// width
var h=480;// height
// comment out if you do not want an exit popup just use doPopUp(); for regular popups
onExitFrames(contentframe);
// ---------------------------------------
// FUNCTIONS// ---------------------------------------
function onExitFrames(myurl) {
 document.write("<FRAMESET ROWS='100%,*' SCROLLING=no BORDER=0 frameborder=no framespacing=0 onunload=doPopUp(",address, ",",fs,",",w,",",h,")>")
 document.write("<FRAME src="+myurl+" SCROLLING=auto BORDER=0 frameborder=0>");
 document.write("<FRAME src="+this.location.url+" SCROLLING=no name=VSmall BORDER=0 frameborder=0></frameset>");
}
// normal popup
function popup(address, mylocation, mystatus, mytoolbar, scrollbar, w, h) {
  var extra = "location="+ mylocation +",status="+ mystatus +",toolbar="+ mytoolbar +",width="+ w +",height="+ h +",scrollbar="+ scrollbar;
  window.open(address,'newwindow',extra);
}
// fullscreen popup (netscape safe, hopefully)
function fullscreen(address) {
  if (detectBrowser()=="IE") {
    window.open(address, 'newwindow', 'fullscreen=yes,scroll=no');
  } else {
    mywindow = window.open(address, 'newwindow', 'location=no,status=no,toolbar=no,scrollbar=no,width='+screen.width+',height='+screen.height);
    mywindow.focus();
    mywindow.moveTo(50,50);
  }
}
// detect users agent (browser)
function detectBrowser() {
 if (parseInt(navigator.appVersion) >= 4) {
  if (navigator.appName == "Netscape") {
   browser = "Netscape";
  } else {
   browser = "IE";
  }
 }
 return browser;
}
// set cookie optional expire
function setCookie(name, value, expire) {
 document.cookie = name + "=" + escape(value)
 + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
}
// get cookie value
function getCookie(Name) {
  var search = Name + "="
  if (document.cookie.length > 0) {// if there are any cookies
    offset = document.cookie.indexOf(search)
    if (offset != -1) {// if cookie exists
    offset += search.length
    end = document.cookie.indexOf(";", offset)
      if (end == -1)
       end = document.cookie.length
      return unescape(document.cookie.substring(offset, end))
    }
  } else {
    return false;
  }
}
//execute all functions together to perform a popup
function doPopUp(address, fs, w, h) {
  if (getCookie('popup')==false) {
    setCookie('popup',this.location.href);
    if (fs) {
      fullscreen(address);
    } else {
      popup(address,'no','no','no','no',w ,h);
    }
  }
}
// stop hiding -->
</script>


</head>
<body>
<BR><center><a href='http://www.js-examples.com'>JS-Examples.com</a></center>
</body>
</html>
0
 
LVL 8

Expert Comment

by:fozylet
ID: 9647033
I think you just copy-pasted the code from the URL i posted Xxavier... correct me if i'm wrong.
0
 
LVL 7

Expert Comment

by:Xxavier
ID: 9647086
  I have had that code for ages if you notice there are only 3 mins between the posts, when I submited it seemed if I was going to be the first post.. For me to have done what you say I must have opened this question at the instant you posted, located the code, copied it,  edited it, (it is not quite the same) and posted all in under 3mins.   So next time you accuse people of doing things check the facts of the situation please.

(at least I posted code and saved the questioner the effort of getting it, a small gesture but I always appreciate it when it is done for me)
0
 
LVL 9

Author Comment

by:CFDevHead
ID: 9647255
Hold on
0
 
LVL 9

Author Comment

by:CFDevHead
ID: 9647274
Tried both examples and no luck?
0
 
LVL 9

Author Comment

by:CFDevHead
ID: 9647312
Xxavier,

Your example asumes that everything is going to go through framesets which is not the case.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 9

Author Comment

by:CFDevHead
ID: 9647354
I need a script that run when the user leaves the domain.
0
 
LVL 8

Expert Comment

by:fozylet
ID: 9647369
Xxavier,

i apologise.
0
 
LVL 8

Expert Comment

by:fozylet
ID: 9647377
dint paste the code as it may involve copyright issues...
even code we are free to use may not always be free to post.
Am not really sure of this case, am just telling you one reason why i dint post the code.
0
 
LVL 7

Expert Comment

by:Xxavier
ID: 9647393
CFDevHead,
   That is the only way it can be done. Your pages are shown within a frame and any link within you domain must have the frame as the target. The frame is a single frame and is not noticable to the user. Any external links must have target for the target set to the parent so that on close the popup is fired, the same happens when a url is typed into the address bar, the cookies take care of multiple popups.
0
 
LVL 9

Author Comment

by:CFDevHead
ID: 9647433
Are sure there is no way to do such a thing?  I was told there was.
0
 
LVL 12

Accepted Solution

by:
jyokum earned 500 total points
ID: 9647519
admittedly, this is some strange code... but it seems to work


<!--    closeDomain.html   -->
<html>
<head>
<script>
function checkExit(){
     var win = window.open("","","width=10,height=10");
     win.blur();
     win.document.write("<script>");
     win.document.write("setTimeout(\'checkDomain()\',1000);\n");
     win.document.write("function checkDomain(){ ");
     win.document.write("try {");
     win.document.write("if(window.opener) var x = window.opener.location.href;\n");
     win.document.write("self.close();}");
     win.document.write("catch(e){window.alert(\'you left my domain!!!\'); self.close();}");
     win.document.write("}");
     win.document.write("<\/script>");
}
</script>
</head>

<body onunload="checkExit();">
<a href="closeDomain.html">stay at domain</a><br>
<a href="http://www.experts-exchange.com">leave domain</a><br>
</body>
</html>
0
 
LVL 7

Expert Comment

by:Xxavier
ID: 9647563
Hmm, perhaps it can be done, very clever.
0
 
LVL 7

Expert Comment

by:Xxavier
ID: 9664967
fozylet,
      I have just noticed you post concerning our coincidental posts, thanks. These things happen. You are right there are copy right issues, I have had that code in my library from somewhere else and was not aware it had the header.

Xxavier :-)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now