[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

javascript redirect when onunload

Posted on 2010-08-19
3
Medium Priority
?
951 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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 learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

656 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