How to exit Kiosk Mode in Edge programmatically - javascript

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.

Related

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

Debugging JavaScript in popup windows on Chrome

What is a good way to debug a popup window in Chrome? I need to debug some code that is run when the window is opened and I was wondering if there was a better way to debug it than pressing f12 as soon as the window opens. I'm looking for something similar to using Visual Studio where you can open a window, set a breakpoint on some JS, then open the window back up and VS will break on that breakpoint without you having to do anything.
If it can be done some way on Firefox I'd switch to that, as long as I don't have to use IE.
Nowadays there's an option in the Chrome devtools settings. "Auto-open DevTools for popups".
Check that checkbox, then if you have devtools open on the parent window and that opens a popup or new tab devtools will automatically open in that window/tab.
Short Answer:
"Ctrl + click"
Long Answer:
I had the same problem. It seems that it's a bug in Google Chrome and there's nothing we can do about it until it is fixed in future versions. I found a way around it, though, which is not an actual solution but solved my problem.
1) Close the popup window.
2) Open it again using "Ctrl + click" instead of just clicking on the link to the popup window.
3) The window will be opened in a new normal tab.
4) Now you can press F12 and go to debug mode.
Hope this solves someone else's problem too.

JavaScript close window for external URL

In my page when I click on a link a popup will be opened. In that popup, I have the close button. To close the window I am using simple JavaScript function as window.close().
This is working fine.
Now when I copy the URL of the popup link and open it in new window, I am not able to close the window.
In Firefox when using Firebug the warning given is:
'Scripts may not close windows that were not opened by script.'
Please help me out on any other alternative.
Firefox seems to answer that question: 'Scripts may not close windows that were not opened by script.'
This is a security measure. Imagine every site could close every other page you have open, that wouldn't work very well would it?
That's why only a parent window may close its children windows.
There may be a setting Firefox that allows windows not opened by script to be closed by script, but even if there is, what chance is there that your visitors will all have enabled this setting?
You can't work around this problem, it is how Firefox (and certainly other browsers) works. The only answer is to change your approach.
Why are you using windows as popups anyway? This has not been recommended for some time now and is mostly frowned upon. Popups that are actual windows may be blocked by popup-blockers.
You should probably use a modal popup instead of a window

How to close the browser window?

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.

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