Entry
i+want+to+show+message+only++when+a+customer+leave+from+my+site.There+are+3+pages+in+my+site
Apr 8th, 2008 18:07
ha mo, joy chatterjee, Colin Fraser, Becky Smiths,
Your question is not very clear, but there are a couple of things that
come to mind. The first question is to ask why do you want to replace
the next url the user wants to go to with something different? I am
sure that this would be somewhat annoying to a lot of users so would
not necessarily be a good idea.
It may be better to use this instead :
In the head :
<script language="JavaScript"><!--
function doThis() {
closingWindow = window.open('','closeWin','width=100,height=100,
screenX=200,screenY=200,top=200,left=200');
closingWindow.location.href = 'closure.html';
}
//--></script>
Which opens a window that you can use to say"Goodbye" or whatever
<body onUnload="doThis()">
This calls the window opener when the page is unloaded.
There is also the replace() method, but I would suggest this is asking
for trouble.
<script language="JavaScript"><!--
function goMyurl() {
if (document.images)
location.replace('http://www.this.org/place/is/cool.htm');
else
location.href = 'http://www.this.org/place/is/cool.htm';
}
//--></script>
<body onUnload="goMyurl()">
Replace() will work across all browsers that I have tested, but Opera
only uses absolute URL's.
THe only issue for you is still why do you want to inerfere with the
user's determination to go somewhere else? You want to make your page
gluey, that is ensure all users are stuck in your page? Or is it that
you want to display some sort of advertisement or message when users
leave your site? This is a much more appropriate use of Javascript than
many other pages try, just be careful with it.
The only other thing that comes to mind from your question is that you
want to prompt the user for a URL at some stage in your page and then
you want the browser to be directed to that URL when the current page
is
unloaded. There is a number of problems here, not the least of which is
that few users would even be aware of what URL they want to go to next.
Be that as it may, you could call a prompt and take the url from that
at
the unload event, pretty much as the first example above:
<script language="JavaScript"><!--
function doThis() {
var url = prompt ("What URL do you want","Write it here");
if (document.images)
location.replace(url);
else
location.href = url;
}
//--></script>
Good luck.
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com