0

In a asp.net content page I have a hyperlink and I am making call to window.print.. but its not working, not opening the print window.

<a href="javascript:window.print(); return false;" style="border:none" >
    <input type="image" src="print.png" alt="" />
</a>

any ideas why?

Thanks

Musa
  • 96,336
  • 17
  • 118
  • 137
CoolArchTek
  • 3,729
  • 12
  • 47
  • 76

1 Answers1

3

I suggest not using javascript in the href. Try this instead:

<a href="#" onclick="window.print(); return false;" style="border:none" >
    <input type="image" src="print.png" alt="" />
</a>

Personally, I don't like adding any inline JavaScript to my elements. So, I would do this:

CSS:

#printPage{
    cursor: pointer;
}

HTML:

<input type="image" src="print.png" alt="" id="printPage" />

JavaScript:

document.getElementById('printPage').addEventListener('click', function(){
    window.print();
});

DEMO: http://jsfiddle.net/J5MBt/

gen_Eric
  • 223,194
  • 41
  • 299
  • 337