This question is not the duplicate of if window is popup , But a similar one.
I am developing a extension which injects scripts to all web pages. I need to detect w
For me, i was implementing a Logout screen that could be shown in a window popup via window.open(..) or from a link within a single page.
I needed to determine:
1) if my Logout screen is within a popup, then:
event.preventDefault();
window.close();
2) otherwise use the browser back function..
window.history.back();
My solution: If the page is within a popup, in my case it has a window page history of 1:
event.preventDefault();
if (window.history.length === 1) {
window.close();
} else {
window.history.back();
}