CoolArchTek
CoolArchTek

Reputation: 3849

call to window.print not working in IE

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

Upvotes: 0

Views: 4647

Answers (1)

gen_Eric
gen_Eric

Reputation: 227310

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/

Upvotes: 3

Related Questions