?
Solved

Javascript popup not working with external shopping cart

Posted on 2003-03-11
6
Medium Priority
?
436 Views
Last Modified: 2013-11-29
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.

0
Comment
Question by:creativeGuy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 30

Accepted Solution

by:
third earned 200 total points
ID: 8116687
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.


<html>
<head>
<script>
 var willPopup=true;
</script>
</head>
<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>
</body>
</html>
0
 
LVL 1

Expert Comment

by:MatrixDud
ID: 8116759
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.
0
 
LVL 10

Expert Comment

by:kollegov
ID: 8116819
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">
</frameset>

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

<script>
  function doPopup() {
    // whatever ...
  }
  window.onunload=doPopup
</script>
<body onUnload="doPopup()">
</body>

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


0
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 
LVL 10

Expert Comment

by:kollegov
ID: 8116823
Ooooppsss, MatrixDud proposed the same while I was testing solution with various brousers
0
 
LVL 10

Expert Comment

by:kollegov
ID: 8116833
BTW,  MatrixDud  <frameset onunload="...."> fires in MIE only..
That's was the reason of putting popup code in dummy document in frame
0
 

Author Comment

by:creativeGuy
ID: 8117038
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..
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How important is it to take extra precautions to protect your online business? These are some steps you can take to make sure you're free of any cyber crime.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
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)
Suggested Courses

801 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