onclick cancel another function

I have a function that runs onunload.
Is there a way that when someone clicks a different button on the page, and it runs a different function, is there a way to cancel and make sure the onunload won't run?
rivkamakAsked:
Who is Participating?
 
zappafan2k2Connect With a Mentor Commented:
Try something like this
<script type="text/javascript">
function cancelUnload() {
    window.onunload = null;
    return true;
}
</script>

...

<input type="submit" value="Submit" onClick="return cancelUnload();" />

Open in new window


The value property of your submit button will not affect anything.

If you already have a function that gets called with the onclick, then add the line
window.onunload=null;

Open in new window

to that function, as I suggested above.

If this doesn't help you, then post the code you're using.
0
 
leakim971PluritechnicianCommented:
>is there a way to cancel and make sure the onunload won't run

use a input with type = button
and not a submit button

set the onclick attribute of this button to run the different function
0
 
zappafan2k2Commented:
Try adding
window.onunload=null;

Open in new window

somewhere in your function to cancel the onunload call.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
leakim971PluritechnicianCommented:
<input type="button" onclik="a_different_function()" value="no unload" />

Open in new window

0
 
zappafan2k2Commented:
leakim971,

I think rivkamak is looking for a way to cancel the onunload call.  There seems to already be a function called when a button is clicked.

In your example (onclik should be onclick, I think), in  a_different_function() adding the line I posted above would cancel the onunload function.
0
 
rivkamakAuthor Commented:
My onlick submits the page. But I don't want the onunload to happen when you click the submit button.
If the form submits but I put value="no unload", then the unload wont' happen?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.