browser.close(window handle) - i tried this but its closing the entire window.
How to close a specific tab from a browser window which has multiple tabs using web-driver io.
I am working on chromedriver.
Before closing the last browser tab please make sure at least one tab exists. Just open some tab before closing.
Related
Close the current tab and open a new tab using JavaScript. On Chrome or any other browser.
Try this:
window.open('http://www.google.com','_blank');
window.setTimeout(function(){this.close();},1000);
Close the current tab
You can't close the current tab until and unless it has parent
reference
Its simple, if the current tab is opened by self I mean, you went to browser and typed the url in the url bar can't be closed with the javascript. Because of security reasons browsers will not allow these type of things.
If you try the following code
window.close();
you'll get following warning message by browser
Scripts may close only the windows that were opened by it.
If the tab is opened with window.open, right click on the link and opened on anchor tag then following should work
window.close();
self.close();
Opening new tab using the javascript :
window.open("https://stackoverflow.com");
A new tab opens up when i click a link given in a iframe. Is it possible to close these newly opened tabs by giving some controls in the iframe
Most modern browsers sandbox each tab, preventing the ability to do what you're requesting. As an example, run this jsFiddle and watch your JS console in your browser.
The code will open a new browser tab using JS so we have a little bit of control over it:
var x = window.open('https://www.google.com');
But, when we try to close it:
x.close();
In most browsers you will see an error when you attempt to control navigation or close the window in the second (sandboxed) tab.
I'm writing a Chrome Extension that opens an external (detached) window that is meant to be open for the rest of the session.
I'd like to get an event when the main window (with many tabs) is closing so that I close my tab before the main window. Otherwise, the tab will remain open and the user needs to close it manually. Thus, Chrome will remember it as the next time Chrome will open it instead of the other tabs that were in the main window. Obviously, this is a bad user experience.
The background script doesn't get any event when the main window closes.
Any idea how I could get this?
I need to open a page in a new tab. That page has a XAML app that prints a special barcode we use in our web application. We manage to do that with a simple window.open. The problem is that besides opening the page, IE moves to that tab in stead of staying in the current tab. I've tried
//open the printing window
win2 = window.open('printingPage.aspx');
//set focus back to opener page
win2.blur();
window.focus();
window.document.focus();
but none of that worked. Is there a way to avoid that? I need this to work with IE 9+, we don't care for other browsers nor versions (for now at least).
Thanks in advance!
You can't control how the browser toggles display of the tabs.
If you can inform your users, they can press CTRL before clicking the link or middle click (the scroll wheel on most mice) to open the tab "in the background" but that's about all you can do.
I have an application, in that I want to close the entire browser on clicking on the close button from our application. I tried with the window.close() and self.close() functions but they will be closing the browser if the window is opened from window.open().
Please suggest to me how I can close the browser on clicking on the close button?
You can't. window.close() used to do that in a far past, but browsers don't allow that anymore, going from the concept of that a website should be able to stay open as long as it has to. Eg. a website doesn't end. If you log out, you don't close the window, you simply go back to the home page where you let the user log in again. Same with smartphone apps btw :-)
Most modern browsers will only let you close child windows of a parent. You cannot close the parent window through script.