I tried beforeunload and onunload events but they get called only when user navigate to a different page via address bar not when user close the chrome android browser tab.
I want to send analytics code only when user has closed the page via tab also.
Related
I have a twitter sign in, it's known that Google and Facebook have their own script for opening sign in popup and it somehow works even on Safari, but twitter doesn't. So we implemented our own, the issue we face is that IOS devices are blocking popup opened with:
window.open(url, '_blank', 'height=400,width=800,left=250,top=100,resizable=yes', true);
I've also tried creating an anchor tag after reading (Bypassing popup blocker in safari):
<a id="js__twitter__popup-link" target="_blank" style="visibility: hidden;"></a>
Then we add url to href this.twitterPopupLink.setAttribute('href', url), then document.querySelector("#js__twitter__popup-link").click(), but on IOS it won't open a new page even that way.
Tester said that on iPad popup is opened but using IOS emulators it didn't open for me on iPad. It's a sure thing that it doesn't open popup on iPhone through.
on IOS it won't open a new page even that way
Correct. The point of a popup blocker is to prevent popups. Any workaround you can imagine they've probably also imagined and prevented.
In general, you can only open a popup window in one scenario - immediately after a user-initiated click. Triggering a click via JavaScript won't bypass this.
I'm developing a chrome extension.
The scenario is as follows:
I use background.js that controls the notification settings of my extension.
Content_script.js, which captures information from the current window and inserts an iframe page of the same extension.
Frame_content.js: This is a tab that appears in the right part of the window and that when it is clicked it is displayed.
Example:
step 1
http://oi67.tinypic.com/kcm336.jpg
step 2
http://oi64.tinypic.com/28w1pp3.jpg
I am using chrome.storage.sync to communicate between bg.js , Content_script.js and Frame_content.js and display the tab depending on whether or not it is clicked.
My problem is that when using the listener chrome.storage.onChanged.addListener, it modifies the storage of all chrome windows and open all tabs. I need it to work ONLY in the current window.
That is, when I click on the tab it is displayed in all the browser windows and when I do it small happens the same.
¿Any solution?
I am trying to detect browser or tab close event for Chrome, so that I can invalidate the session for my Java web application. I have tried onbeforeload() and unload(), but these functions are called when the content of page is unloaded within my web application. Also I am unable to override these functions in Javascript for Chrome browser.
Is there any way I can find browser close or tab close event for Chrome and make an ajax call and invalidate the session?
I've surveyed most of the questions on the web but this still gets me confused....
My question is, how to detect hide/leave event of a website tab in mobile phone browser, my situation is NOT about closing the tab(like pressing the X button at the up-right or up-left corner), and also NOT about closing the whole mobile browser app directly.
(Previously, I have a webpage with a websocket connected to receive the encoded audio content, and then use AudioContext to play the sound)
Below are the two situations I've encountered.
When I press the HOME button and the mobile browser app hides.
When I click a url in the Messenger app or Facebook app of my iPhone, and press the Back button to go back.
the url link is opened in the in-app browser which made by Facebook directly, and when I press the back button on the left-up corner, the view jumps back to the Messenger window or the Facebook timeline.
In these two cases, I have listened beforeunload (and also pagehide event for iOS), but neither one is catched. And I have found that the websocket connection is still connecting and the audio is still playing. It seems like the whole page is still running somewhere(but you cannot see). I also tried listening to a div :visible, but it is still giving me true when I pressed the home button or leave the facebook in-app browser.
Is there still any way to detect these two kinds of situation? I want to turn off the streaming sound and also close the websocket connection.
Just found the answer....
Page Visibility API https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
I know how HTML5 notifications work. And I know how to use them in production. But what I can't understand is, the behaviour of Facebook: Even if you close all tabs of facebook, when you receive message, desktop notification appears. Doesn't matter if you use Mac or PC.
How is it possible to execute javascript when there is no open tab (session)?
How does facebook send html5 notifications even if tab closed?