Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to redirect my page(Viewdetails.aspx) to another page(useraction.aspx) before user directly close the browser or the page.

I have written javascript on Viewdetails.aspx page but it doesnt work.

JavaScript
<script language="javascript" type="text/javascript">
   window.onbeforeunload = test;
   function test() {
   window.location = "UserAction.aspx";
   }
</script>

is there any other way for doing this?
Posted
Updated 23-Oct-12 0:31am
v2
Comments
Samsani.v.s.Durga Prasad 23-Oct-12 6:45am    
hi In form onload event of Viewdetails.aspx write

window.location.href="url";
AshishChaudha 23-Oct-12 6:56am    
window.location.href wont work when there is unload event..
Samsani.v.s.Durga Prasad 23-Oct-12 7:19am    
Hi see the code what i posted (solu 2)
[no name] 23-Oct-12 6:47am    
use window.open

Try this
XML
<script type="text/javascript">
window.onbeforeunload = function(){ myUnloadEvent(); }
function myUnloadEvent() {

   window.open("UserAction.aspx");

}
    </script>
 
Share this answer
 
Comments
[no name] 23-Oct-12 6:57am    
my 5
If you close an instance of a browser, there will be no events fired at all. You can't catch an unload event or anything else because it is an application termination at which point page events cease to exist.
 
Share this answer
 
Hi below code will work, i tried

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script type="text/javascript" language="javascript">

        function Redirect() {
            window.location.href = "http://www.dotnetfunda.com";
        }

    </script>

</head>
<body onload="Redirect()">
    <form   id="form1" runat="server">
    <div>

    </div>
    </form>
</body>
</html>
 
Share this answer
 
Comments
AshishChaudha 23-Oct-12 7:30am    
I also tried the same code, not working when browser is closed..I redirecting on page load only.
Samsani.v.s.Durga Prasad 23-Oct-12 7:37am    
is it navigated to www.dotnetfunda.com or not ? while execution of source page

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900