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

 <a href="JavaScript:runPrint(); function runPrint(){window.print();}"><img src="../images/btn_print.gif" alt="Print"  border="0" tabindex="102"></a>


Thanks all for your answers

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

<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.

<script type="text/javascript" src="js/script.js"></script>

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


document.getElementById('printbutton').onclick = function () {
    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.

When people use the horrible javascript: pseudo-protocol, it’s case sensitive. But you can do this a little less filthily:

<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.