onbeforeunload unless i press submit



Hello all

im not a java geek maybe somone can help me

i have this page:
<head>
<title>Untitled Document</title>
<script type="text/javascript">
        function OnBeforeUnLoad () {
            return "Sure you want to exit ?";
        }
    </script>
</head>
<body onbeforeunload="return OnBeforeUnLoad()>
    <form action="" method="get" name="test">
        <input name="test1" type="text" />
        <input name="b1" type="button" />
    </form>
</body>
</html>

now when i exit the page or press submit i get sure you want to exit is it posible to disable message if i press submit ? and only showing it when i try to exit page
nova-cAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ansudhindraConnect With a Mentor Commented:
As far I know it is not possible because, when you submit the form, page reloads..
0
 
ansudhindraCommented:
your code is missing a double quote on line

<body onbeforeunload="return OnBeforeUnLoad()>

try the below code..
 
<head>
<title>Untitled Document</title>
<script type="text/javascript">
        function OnBeforeUnLoad () {
            if(confirm("Sure you want to exit ?")){
              return true;
            }
            return false;
        }
    </script>
</head>
<body onbeforeunload="return OnBeforeUnLoad()">
    <form action="test.html" method="get" name="test">
        <input name="test1" type="text" />
        <input name="submit" type="submit" />
    </form>
</body>
</html>

Open in new window

0
 
nova-cAuthor Commented:
oki thx that was a error when i typed the code here, the code workes on the homepage
but i want it to disable the code when i press the submit button
0
 
nova-cAuthor Commented:
it must be posible to disable the function in java when i press submit
0
 
James MurrellProduct SpecialistCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
All Courses

From novice to tech pro — start learning today.