tane
06-29-2003, 01:38 AM
looking for a script that makes a page pop up after the surfer leaves my homepage not when my homepage loads but when they leave only...thanks
|
Click to See Complete Forum and Search --> : pop up script on exit tane 06-29-2003, 01:38 AM looking for a script that makes a page pop up after the surfer leaves my homepage not when my homepage loads but when they leave only...thanks Mr J 06-29-2003, 11:14 AM <SCRIPT language=JavaScript> var exit=true; function goodbye() { if (exit) open("yourpage.htm"); <!--Place your path and file name here--> } </SCRIPT> Add onunload=goodbye() to the opening <Body> tag <BODY onunload=goodbye()> tane 06-29-2003, 12:18 PM thanks..... tane 07-01-2003, 03:33 AM is it possible to have the exit page only load if they exit at the moment it loads even if the user clicks a link to load another page the exit page still comes up.. I only want it to come up if they exit full stop, if they click on a link from my page i dont want the exit page to load....is that possible?? Mr J 07-01-2003, 11:36 AM You could possibly go: <script> <!-- not_leaving=0 function goodbye(){ if(not_leaving==1){ return } open("yourpage"); <!--Place your path and file name here--> } // --> </script> The above script would have to go in every page then include onclick="goodbye(not_leaving=1)" in all your links <a href="yourpage.htm" onclick="goodbye(not_leaving=1)">LINK 1</a> Still add onunload="goodbye()" to the opening BODY tags Jona 07-01-2003, 11:48 AM Originally posted by Mr J You could possibly go: J, I don't think that would work. I would pass a variable to the function like this: <script type="text/javascript"> <!-- var not_leaving=0; function goodbye(not_leaving){ if(not_leaving==1){return;} window.open("yourpage"); //Place your path and file name here } // --> </script> <a href="yourpage.htm" onclick="goodbye(1);">LINK 1</a> If you have many links on the page, you may want to use JavaScript to populate their onClick functions dynamically. (E.g., a for() loop to go through all of the links on the page and set their onClick functions to goodbye(1);.) [J]ona nkaisare 07-01-2003, 12:23 PM Older days, this would be another site I wouldn't want to visit. But now, I am equipped with Opera. Throw all the popups you want, world! I am ready for you!! :D Jona, I think that you may be confusing scope of the variable not_leaving. I don't know javascript much, but based on my programming knowledge, for the function function goodbye(not_leaving) scope of this not_leaving variable is limited to the function... this variable is different from the external variable defined as not_leaving=0; You may have function goodbye(not_leaving) { if(not_leaving) { return;} window.open("popup.html"); } Note that onclick, you'll call goodbye(1)... But will browser execute this function twice - once onclick and next onunload? If it does, this method wont work. Jona 07-01-2003, 12:30 PM Originally posted by nkaisare Older days, this would be another site I wouldn't want to visit. But now, I am equipped with Opera. Throw all the popups you want, world! I am ready for you!! :D I agree with you. I never make use of popups unless, for example, there is a need for it. But 99% of the time, I go with something else. Originally posted by nkaisare Jona, I think that you may be confusing scope of the variable not_leaving. I don't know javascript much, but based on my programming knowledge, for the function function goodbye(not_leaving) scope of this not_leaving variable is limited to the function... this variable is different from the external variable defined as not_leaving=0; That is incorrect. What I have done is set not_leaving as a global variable, with a value of zero. When you click a link, it will set not_leaving to 1, thus returning the function and stopping before it goes on to opening a new window. Although, I did forget to mention the slight change in the onUnload function: <body onUnLoad="goodbye(0);"> [J]ona nkaisare 07-01-2003, 12:43 PM Originally posted by Jona <body onUnLoad="goodbye(0);"> In which case, you do not need to pre-define it as a global variable. BTW, when one clicks a link, and there are onclick and onunload event handlers, wouldn't both of them be called? In that case, onclick will not cause a popup, but onunload will. I guess you should not pass not_leaving as a variable to the function; instead you should have <a onclick="not_leaving=1; goodbye()">... Mr J 07-01-2003, 12:43 PM J, I don't think that would work I tried it before I posted it and it worked Jona 07-01-2003, 12:45 PM Well, like I said, I didn't think it'd work. I never tried editing a variable while passing it to the function. Never mind what I said, then. ;) ...And I hate popups anyways. :D [J]ona Mr J 07-01-2003, 12:47 PM I don't know wether it is a standard proceedure but I have done it with more than one script and it's always worked Jona 07-01-2003, 12:48 PM Originally posted by Mr J I don't know wether it is a standard proceedure but I have done it with more than one script and it's always worked Have you tested it in all browsers? (Including NN4.) [J]ona Mr J 07-01-2003, 01:02 PM I have tried it in IE5.5 and NS7 NN4 will not be around forever and only delays the inevitable Jona 07-01-2003, 01:05 PM I know, but I was just wondering if you had tested in NN4. Netscape (the browser) is supposedly going out of "business." [J]ona Mr J 07-01-2003, 01:33 PM Sorry but I only have IE5.5 and NS7 Jona 07-01-2003, 01:36 PM Originally posted by Mr J Sorry but I only have IE5.5 and NS7 I didn't mean to come on that strong. I was just wondering which browsers you tested it in, not trying to tell you to get all of the browsers that exist or anything. :) [J]ona Mr J 07-01-2003, 02:34 PM No malice intended there jona :) :D :D :D Jona 07-01-2003, 02:41 PM Originally posted by Mr J No malice intended there jona :) Is there any? :confused: You showed me something that I never thought about... No malice involved. :) [J]ona Mr J 07-01-2003, 03:01 PM Cool :cool: webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |