views:

976

answers:

5

For some reason, in Internet Explorer 6, I cannot get window.print(); to actually work within jQuery. Any ideas why this isnt working?

<script> 
 $(document).ready(function(){ 

function print() { 
 window.print(); 
 return false;
} 

$("a#test").click(function() { 
 print(); 
 }); 

 }); 
</script>

Here is my jsbin: http://jsbin.com/ukoyo/

Also, it seems that window.print(); will not work with Multiple IE.

+1  A: 

Works for me in IE6 on XP SP3.

Multiple IE solutions are generally wobbly. Virtual machines are a much more reliable way to test.

(Note if you have an element with id/name 'print' on the page, IE will incorrectly make ‘window.print’ refer to that element, overriding the method that was previously there.)

bobince
A: 

instead of calling a print function that calls window.print try this instead. If it works, you know the problem is somewhere else

$("a#test").click(function() { 
 window.print(); 
});
slf
A: 

Seems you just redefined the function print(), then calling window.print just called again your own function.

Did you get a "Out of memory" runtime error?

Rodrigo
That's what I thought at first, but actually the definition is inside a `(function(){`...`}()` block so it doesn't go into the `window` scope. (The indentation could be more consistent to make this obvious.)
bobince
A: 

Multiple IEs are totally not the same as the real thing. I would recommend a Virtual machine such as VirtualBox or even Tredosoft's standalone versions.

As for the code I'd do something like this ( your code works though ):

.click(function(e) {
    e.preventDefault();
    print();
});
meder
A: 

I also had the above issues. For more reliable browser testing, try this:

http://spoon.net/Browsers/

Works for me much better than IE collections and others.

keniled