Link to home
Start Free TrialLog in
Avatar of CFDevHead
CFDevHead

asked on

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.
Avatar of fozylet
fozylet
Flag of India image

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>
I think you just copy-pasted the code from the URL i posted Xxavier... correct me if i'm wrong.
  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)
Avatar of CFDevHead
CFDevHead

ASKER

Hold on
Tried both examples and no luck?
Xxavier,

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

i apologise.
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.
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.
Are sure there is no way to do such a thing?  I was told there was.
ASKER CERTIFIED SOLUTION
Avatar of jyokum
jyokum
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hmm, perhaps it can be done, very clever.
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 :-)