[wp-hackers] Adding onclick event to Publish button

James Davis james at freecharity.org.uk
Tue Jul 8 22:01:45 GMT 2008


I'm not at all experienced with Javascript so I'm guessing that this  
will turn into less of a WordPress problem and more of a javascript  
problem. I'm looking to run a javascript function when the publish  
button on the post editor page is clicked. I came up with the  
following which doesn't appear to work.

function tc_print_js() {
     ?>
     <script type='text/javascript'>
         var el = document.getElementById("publish");
         el.onclick = showTC;
         function showTC() {
             //do stuff here...
             window.open("www.google.com");
         }

     </script>
     <?php
}

add_action('admin_print_scripts-post-new.php','tc_print_js');
add_action('admin_print_scripts-post.php','tc_print_js');

A little debugging seems to indicate that  
document.getElementById("publish") returns null but I've got idea why.  
Any suggestions?

Thanks,

James


More information about the wp-hackers mailing list