Search code examples
javascriptjqueryfocusprintdialog

Click link after focus is returned from print dialog


I have a web page that brings up the print dialog on load. After clicking print (and focus returning to the page) I need a link to be clicked. Does anyone know a way using jQuery or Javascript that I can do this?

This is what I currently have, but it doesn't seem to be working:

<script type="text/javascript">
    $(document).ready(function() {
        window.print();
        $("body").bind("focus", function(){ $("#logout").click() });
    });
</script>

Solution

  • try this:

    <script type="text/javascript">
        $(document).ready(function() {
            if (window.print()) 
                location.href = $("#logout").attr('href');
            else
                location.href = $("#logout").attr('href');
        });
    </script>
    

    and

    <body>
        <a id="logout" href="http://www.google.it">Link</a>
    </body>