How to test whether window.print() is not overriden?
-
04-07-2021 - |
質問
How to test with (JavaScript and/or) FirefoxDriver whether the window.print()
method is overridden?
It is possible to disable all print buttons on a page like with this:
window.print = function() { alert("Bazinga") }
With this a normal "Print" link like the following one is not working anymore:
<a onclick="window.print()">....</a>
I need to check whether a window.print()
call executes the original print dialog.
Maybe it is possible to inject some JavaScript into the FirefoxWebdriver?
解決
I've created a fiddle based on Luca's answer and Christoph's comment. This function will detect native print dialog even in IE6.
function isNativePrint() {
var isNative = false;
try {
if (window.print.toString().indexOf('[native code]') > -1) isNative = true;
} catch (e) {
isNative = true;
}
return isNative;
}
他のヒント
Since window.print is a native function you can:
if( window.print.toString().indexOf('[native code]') > -1 ) {
//native
}
所属していません StackOverflow