Close print preview window from google chrome extension project using jquery

僤鯓⒐⒋嵵緔 提交于 2019-12-13 03:46:06

问题


I am making google chrome extension project, where i need to close print preview window from my jquery code. Print preview window open automatically when i call site option from my google chrome extension project.

I have also try with --disable-print-preview. in this case open print popup. so if anyone have idea to close print popup with jquery then it's also suitable for me.


回答1:


[ I have found the solution to cancel the browser print preview screen. here is the solution provided in Java by "Erçin Akçay"

// Choosing the second window which is the print dialog.
// Switching to opened window of print dialog.
driver.switchTo().window(driver.getWindowHandles().toArray()[1].toString());

// Run javascript code for cancelling print operation.
// This code only executes for Chrome browsers.
JavascriptExecutor executor = (JavascriptExecutor) driver.getWebDriver();
executor.executeScript("document.getElementsByClassName('cancel')[0].click();");

// Switches to main window after print dialog operation.
driver.switchTo().window(driver.getWindowHandles().toArray()[0].toString());



回答2:


You just need to disable the print preview using given line below. You can use before clicking on the print button.

((JavascriptExecutor)driver).executeScript("window.print=function(){};");



来源:https://stackoverflow.com/questions/47885424/close-print-preview-window-from-google-chrome-extension-project-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!