I am trying to provide a button to open a browser level print dialog on a window. I first tried window.print(); with an inline "onclick" on an <input>
and then a click() function on the input using jQuery, and both give the same error when clicked:
TypeError: Property 'print' of object [object global] is not a function
I should point out that this is a popup window, but I wouldn't have thought that would matter except that any form of using window.print() on the parent page works fine.
Seemed like something must be happening to the window object somewhere, so I did the following in console:
window.name
"JOIN"
window.self
Window {top: Window, window: Window, location: Location, external: Object, chrome: Object…}
window.location
Location {assign: function, replace: function, reload: function, ancestorOrigins: DOMStringList, origin: "http://local.xxx.xxx:8080"…}
So it SEEMS like the window object is there and defined as expected.
I can even run other methods like close(), confirm(), alert(), scrollTo(), etc on this same window object and they work fine. So why wouldn't print()?
The contents of the page don't seem to matter, and I will also say we are not using iFrames or frames. I did replace ALL the content of the popup with just
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head></head>
<body>Foo</body>
</html>
with the same results. So I'm fairly certain none of our other code is interfering.
EDIT
The code that I was using to trigger print():
$('.foobar').click(function(){
window.print();
});
tho now I'm just doing it in console.
The button
<input type="button" class="foobar" value="Print" />
This would happen if you have an element with an id of print
.
Element IDs become properties of the window
(the global object), hiding any existing members with the same name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With