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

Javascript popup not working with external shopping cart

I have a website that uses an external shopping cart. I want to use popUp ads when the visitor leaves the website, which can be done with onUnload but the problem comes as follows:

when the visitor adds a product from the main website into its shopping cart, the url changes to the external shopping cart address. This trigers the popUp ad to be displayed, which shouldn't display when the external shopping cart address is loaded in the browser window. Instead the popUp should display when either the browser window is closed or any other url is loaded.

Any help would be appreciated and ofcourse the points would be awarded. Thanks in advance.

1 Solution
there's no neat way of doing this but i will give you an  example. you have to put a flag in each of the links in your page where you don't want the popup to comeout. this works but not during,
1.) the user refreshed your page.
2.) the user manually typed the url on the address bar.
3.) the user click the back/forward button.

 var willPopup=true;
<body onunload="if(willPopup)window.open('http://www.experts-exchange.com');">
  <a href="home.html" onclick="willPopup=false;">home</a>
  <a href="services.html" onclick="willPopup=false;">services</a>
  <a href="products.html" onclick="willPopup=false;">products</a>
The onUnload event will trigger whenever the current <body> is wiped out or refreshed. Technically when you surf elsewhere, even within your site, you unload the page. They really should have an onClose() event but that opens up a whole other discussion on ethics and what our favourite warez sites will do with it.

Another way you can tackle this issue, other than the previous post, which is the most common method, is to use a frameset with one frame. In the frameset you can put all of your scripts and whatnot. In the frameset tag you put your onUnload event. Really the frameset should only unload if the user exits your site completely or you have a link that has a target of _top.
other way is to use frames

<frameset cols="0,*" border=no frameborder=0 framespacing=0 >
   <frame src="dummy.html">
   <frame name="main" src="main.html">

All your navigation will happens in main frame do not causing unload of frameset window itself
and dummy frame,   But closing of window will rise popup

and in dummy.html do

  function doPopup() {
    // whatever ...
<body onUnload="doPopup()">

Same limitations, popup will rise when frameset window reloads
but you do not need to modify all links allover site

Industry Leaders: 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!

Ooooppsss, MatrixDud proposed the same while I was testing solution with various brousers
BTW,  MatrixDud  <frameset onunload="...."> fires in MIE only..
That's was the reason of putting popup code in dummy document in frame
creativeGuyAuthor Commented:
Pretty simple but creative solution...it works great, i couldn't have used the frames as well but that has it's own limitations...anyways, thanks to all who replied, i really appreciate it and thanks and 50 points to third..

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now