use javascript to terminate firefox browser - javascript

i programmatically start a browser, running firefox, from a windows application. i want to add a button and connect the button, using javascript, to an onClick event to terminate the browser. I did try window.Close(), but that does not work. the order of events is as follows: app -> start firefox -> runs my own js script -> on the script i have an exit button -> depress exit button -> firefox terminates and control back to the app.

$(element).click(function(){ window.close(); });
Note: you cannot close any window that you didn't open with window.open . Directly invoking window.close() will ask user with a dialogue box.

Related

How to exit Kiosk Mode in Edge programmatically

I'm developing a system that runs in Edge (school's default browser), the browser launches in Kiosk mode from a desktop shortcut
"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --kiosk www.program-name.com --edge-kiosk-type=fullscreen
On the landing page, I can exit the program no problem with a close button using
<input type="button" onClick="window.close();" value="Close">
Once you proceed into the program, next page onwards, window.close no longer works. The only way to quit is by using Alt + F4 or pressing the Start key and right clicking the Edge icon
If you open the Developer Tools console, you'll find this message when the window doesn't close by window.close():
Scripts may close only the windows that were opened by them.
The message is clear. There're some restrictions when using window.close() to close window. In Chromium, window.close() succeeds if the new window/tab has an opener or if the back/forward stack contains fewer than two entries. The limitation of window.close() is for security and user-experience. For more detailed information, you can refer to this blog.
The only way to close the proceed window programmatically is opening the window by window.open(). For example, if you want to open a new window by clicking a link, you can use the code like below:
link
Then on test.html you can use window.close() to close the window.

Why is window.close() suddenly not working?

My application opens new PHP from an icon or link in a new browser tab. For several months now, I've been using a simple JavaScript function to close the current browser tab.
Suddenly, over the past few days, the Close link only works when the Window is first opened. The moment you do something on the page (click a link, press a submit button), it doesn't work. I'm at a loss as to what the problem can be. Nothing has changed in the code.
The HTML href statement is:
<span>Close</span>
And the JavaScript function is:
function windowClose() {
window.open('','_parent','');
window.close();
}
This is happening with both Edge and Chrome on a Windows 10 platform.
Could it be caused by some update to the O/S, Chrome or Edge application?
According to MDN, "scripts can not close windows, they had not opened"
If the tab has been opened by you (you typed the url and hit enter manually), there's no way you can close the window with Javascript. However, if for instance, you started your project with npm start (React in my case), the page can be closed with the code you've provided. Though when you try to re-do it by manually opening the webpage and closing the tab - you will fail.
All in all, don't try to close the window that was not opened by js.
Reference: https://developer.mozilla.org/en-US/docs/Web/API/Window/close#closing_the_current_window

How to storeConfirmation in popup SeleniumIDE

Can u help me about StoreConfirmation for popup SeleniumIde ? + example command.
please answer only selenium IDE.
Thanks
If you are talking about default javascript alert or confirmation there are two commands for it:
storeAlert
Returns:
The message of the most recent JavaScript alert
Retrieves the message of a JavaScript alert generated during the
previous action, or fail if there were no alerts.
Getting an alert has the same effect as manually clicking OK. If an
alert is generated but you do not consume it with getAlert, the next
Selenium action will fail.
Under Selenium, JavaScript alerts will NOT pop up a visible alert
dialog.
Selenium does NOT support JavaScript alerts that are generated in a
page's onload() event handler. In this case a visible dialog WILL be
generated and Selenium will hang until someone manually clicks OK.
storeConfirmation
Returns:
the message of the most recent JavaScript confirmation dialog
Retrieves the message of a JavaScript confirmation dialog generated
during the previous action.
By default, the confirm function will return true, having the same
effect as manually clicking OK. This can be changed by prior execution
of the chooseCancelOnNextConfirmation command.
If an confirmation is generated but you do not consume it with
getConfirmation, the next Selenium action will fail.
NOTE: under Selenium, JavaScript confirmations will NOT pop up a
visible dialog.
NOTE: Selenium does NOT support JavaScript confirmations that are
generated in a page's onload() event handler. In this case a visible
dialog WILL be generated and Selenium will hang until you manually
click OK.
You can see working example here : http://www.software-testing-tutorials-automation.com/2013/10/selenium-ide-what-is-use-of.html
Hope it will help you.

Running a method on browser close tab or browser exit

Is there an action handler I can use in Javascript+Angular+JQuery that makes it possible to schedule a method to be executed just before a tab is closed in the web browser?
By close I mean quitting the browser or closing the tab or crashing or anything...
Yeah, you just bind the the beforeunload on the window object.
angular.element($window).bind("beforeunload", exitHandler)

Android browser run javascript window.close()?

Is it possible to close an Android browser window with window.close() or something related? I can't get anything to work on Android (on desktop browsers Chrome and Firefox I can window.close() without problems).
Thanks
Unfortunately, No.
I have a situation where I launch the zxing scanner app from my browser. It returns in a new browser window. I snag the data but then need to close that tab. And have yet to find a solution to get that tab closed, either through a user clicking a button on the page or in the body load. So it seems you can only put instructions on the page to have the user close the tab.

Categories