SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    window.print problem in IE7

    Hello All,

    The below is my code and this is not working in IE7 Could you please let me know why . I tried to find but i cannt


    Code:
     <a href="JavaScript:runPrint(); function runPrint(){window.print();}"><img src="../images/btn_print.gif" alt="Print"  border="0" tabindex="102"></a>
    Thanks,
    Arun
    Where there is a will there is a way
    ArunKumar

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    When people use the horrible javascript: pseudo-protocol, it's case sensitive. But you can do this a little less filthily:

    HTML Code:
    <a href="#" onclick="window.print(); return false;"><img src="../images/btn_print.gif" alt="Print"  border="0" tabindex="102"></a>
    You could improve on that by using unobtrusive javascript. Look it up.

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Here's how to do it with unobtrusive JavaScript.

    First, provide a way for scripting to access the HTML element, in this case by applying a unique identifier

    Code html4strict:
    <a id="printbutton" href="#"><img src="../images/btn_print.gif" alt="Print"  border="0" tabindex="102"></a>

    The tabindex should not be necessary, and CSS should definately be used for the border, but you can sort those out later.

    Next, use JavaScript at the end of the body, so that it can easily target the above link.

    Code html4strict:
    ...
    <script type="text/javascript" src="js/script.js"></script>
    </body>
    </html>

    Then with scripting, get the above link and attach the event on to it.

    js/script.js
    Code javascript:
    document.getElementById('printbutton').onclick = function () {
        window.print(); 
        return false;
    }

    If you want to get really unobtrusive, the HTML link in the first block of code won't be useful unless scripting is enabled, so you can remove the HTML link from the HTML code and use scripting instead to create it. But that's another story.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks all for your answers
    Where there is a will there is a way
    ArunKumar


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •