?
Solved

javascript redirect when onunload

Posted on 2010-08-19
3
Medium Priority
?
950 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
[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
3 Comments
 
LVL 22

Accepted Solution

by:
Mrunal earned 2000 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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

765 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