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?
Who is Participating?
zappafan2k2Connect With a Mentor Commented:
Try something like this
<script type="text/javascript">
function cancelUnload() {
    window.onunload = null;
    return true;


<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

Open in new window

to that function, as I suggested above.

If this doesn't help you, then post the code you're using.
>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
Try adding

Open in new window

somewhere in your function to cancel the onunload call.
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

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

Open in new window


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.
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?
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.