JavaScript javascript open popup before closing the current tab javascript open popup window,javascript open popup window center,javascript

I want to open a popup when the user closes the last tab of the current site. The problems I have is that

  • when the browser prompts the user (onbeforeunload returning a non null value), then the popup is blocked by the browser (see case 1 below)
  • when the browser does not prompt anything to the user (onbeforeunload not returning anything), then the popup is not opened at all and seemed to be totally ignored by the browser (why is that?) (see case 2 below)

Case 1: prompt and popup blocked (code from this answer)

window.onbeforeunload = function (e) {
    e = e || window.event;

    window.open('http://localhost', '_blank');

    // For IE and Firefox prior to version 4
    if (e) {
        e.returnValue = 'Sure?';
    }

    // For Safari
    return 'Sure?';
};

Case 2: no prompt, no popup, page closing "normally"

window.onbeforeunload = function (e) {
    e = e || window.event;

    window.open('http://localhost', '_blank');
};
Answer:1

From the specification:

An algorithm is allowed to show a popup if any of the following conditions is true

The task in which the algorithm is running is currently processing an activation behavior whose click event was trusted.

The window closing is not a click event.

The task in which the algorithm is running is currently running the event listener for a trusted event whose type is in the following list:

unload is not in that list.

The task in which the algorithm is running was queued by an algorithm that was allowed to show a popup, and the chain of such algorithms started within a user-agent defined timeframe.

For example, if a user clicked a button, it might be acceptable for a popup to result from that after 4 seconds, but it would likely not be acceptable for a popup to result from that after 4 hours.

Again, no. The task wasn't queued.

It is not possible to open a popup in response to a user trying to leave your site. It would enable too many harmful behaviours (click on this advert, quit, popup, you must click on this advert, loop).

Answer:2

I have a div and I am trying to display a text with bold font as follows: $('#div').text("data between "+ fromdate + "to" + todate).css({'text-align':'centre'}); How do I display only "fromdate" and ...

I have a div and I am trying to display a text with bold font as follows: $('#div').text("data between "+ fromdate + "to" + todate).css({'text-align':'centre'}); How do I display only "fromdate" and ...

  1. change style inside iframe
  2. change style inside div
  3. change style inside html
  4. css change style inside iframe
  5. jquery change style inside iframe
  6. change element style inside iframe
  7. change font style inside table html
  8. change css style inside html
  9. html change style inside span

I have a HTML structure like this: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <table id ="x"> <tr> <td class='col1'> ...

I have a HTML structure like this: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <table id ="x"> <tr> <td class='col1'> ...

I have a form in which certain calculations are happening as per the dropdown selected. Everything is working fine except that when i select a value from dropdown price/unit field has to be filled by ...

I have a form in which certain calculations are happening as per the dropdown selected. Everything is working fine except that when i select a value from dropdown price/unit field has to be filled by ...

sorry but I'm new in javascrit. I'm writing a simple rss reader, but I want to limit the number of feeds to 5 items, because the my target site can have 100 or more. Here the code: $("#mainPage")....

sorry but I'm new in javascrit. I'm writing a simple rss reader, but I want to limit the number of feeds to 5 items, because the my target site can have 100 or more. Here the code: $("#mainPage")....

  1. javascript limit number of characters
  2. javascript limit number of decimals
  3. javascript limit number range
  4. javascript limit number to 2 decimal places
  5. javascript limit number of checkboxes selected
  6. javascript limit number of words
  7. javascript limit number to 1 decimal place
  8. javascript limit number of characters in textbox
  9. javascript limit number of characters in input
  10. javascript limit number
  11. javascript limit number of decimal places
  12. javascript limit number input
  13. javascript limit number length
  14. javascript limit number of digits
  15. javascript limit number of lines in div
  16. javascript limit number to 2 decimals
  17. javascript limit number of lines in textarea
  18. javascript limit number of characters in div
  19. javascript limit number of events
  20. javascript limit number of characters in textarea