Solved

javascript redirect when onunload

Posted on 2010-08-19
3
949 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

729 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