• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 697
  • Last Modified:

popup window unpon exit of domain only

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
CFDevHead
Asked:
CFDevHead
  • 5
  • 5
  • 4
  • +1
1 Solution
 
XxavierCommented:
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
 
fozyletCommented:
I think you just copy-pasted the code from the URL i posted Xxavier... correct me if i'm wrong.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
XxavierCommented:
  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
 
CFDevHeadAuthor Commented:
Hold on
0
 
CFDevHeadAuthor Commented:
Tried both examples and no luck?
0
 
CFDevHeadAuthor Commented:
Xxavier,

Your example asumes that everything is going to go through framesets which is not the case.
0
 
CFDevHeadAuthor Commented:
I need a script that run when the user leaves the domain.
0
 
fozyletCommented:
Xxavier,

i apologise.
0
 
fozyletCommented:
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
 
XxavierCommented:
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
 
CFDevHeadAuthor Commented:
Are sure there is no way to do such a thing?  I was told there was.
0
 
jyokumCommented:
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
 
XxavierCommented:
Hmm, perhaps it can be done, very clever.
0
 
XxavierCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now