Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am writing a plugin that adds a custom metabox to the post page. I would like to trigger an event when the user navigates away from the edit post page or when a user stops editing a specific post. Is there a way to listen to events on the post page?

share|improve this question
1  
What exactly is stops editing...? –  kaiser Nov 27 '12 at 16:03
    
After I have saved (published or abandoned) my post and navigated away to a different post, or closed wordpress all together –  Olympian Nov 27 '12 at 17:54
    
Interesting question. I'm coming up empty. I first thought about using javascript and onbeforeunload, but the post editing page already uses that. Then I thought that maybe you could hook into whatever process releases the editing lock, but I actually couldn't find it. If anyone has more time to look into this, I think that's probably the best route. –  Matthew Boynes Nov 29 '12 at 22:05
add comment

1 Answer

This is more of a JavaScript the A WordPress Question but anyway, You can use the JavaScript onbeforeunload event something like:

<script type="text/javascript">
    old = window.onbeforeunload;
    window.onbeforeunload = MyOnExit;
    function MyOnExit(){
        //do your stuff here
        return old();
    }
</script>    
share|improve this answer
1  
I think you need "return old();" as a non-null return value triggers the prompt. –  Simon Gibbs Apr 9 '13 at 10:27
    
THanks updated! –  Bainternet Apr 9 '13 at 10:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.