Solved

javascript redirect when onunload

Posted on 2010-08-19
3
938 Views
Last Modified: 2013-11-19
I'd like my page to redirect a user to a specific page onunload. Like this:

<body onUnload="window.location = 'http://www.google.com/'">

but this doesn't really seem to be working. Any ideas?

Thanks
0
Comment
Question by:elliottbenzle
3 Comments
 
LVL 22

Accepted Solution

by:
Mrunal earned 500 total points
ID: 33475897
first try this:

<body onunload="alert('sad')">

if got alert then it should work.

<script>
function Redirect() {
var where=URL TO BE REDIRECTED TO;
window.location=where;
}
</script><body onUnLoad="Redirect()">
0
 
LVL 4

Author Closing Comment

by:elliottbenzle
ID: 33476098
Works great. Thank you.
0
 

Expert Comment

by:audibuild
ID: 33476510
You could always try something like this:

<script>
function closeIt()
{
  window.location='http://google.com';
  return true;
}
window.onbeforeunload = closeIt;
</script>

A potential drawback is that you are prompted with a "Are you sure you want to navigate away from this page?" dialog box.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now