[wp-hackers] Adding onclick event to Publish button

Viper007Bond viper at viper007bond.com
Wed Jul 9 07:15:51 GMT 2008


jQuery is your friend.

<script type="text/javascript">
/* <![CDATA[ */
    jQuery(document).ready(function() {
        jQuery("#publish").click(function() {
            alert("Publish button was clicked.");
        });
    });
/* ]]> */
</script>

On Tue, Jul 8, 2008 at 3:01 PM, James Davis <james at freecharity.org.uk>
wrote:

> 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
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
Viper007Bond | http://www.viper007bond.com/ | http://www.finalgear.com/


More information about the wp-hackers mailing list