How to force alert window to pop-up - javascript

After several time showing alert window the browser ask whether to prevent creating additional dialog.
Is there a way to force JavaScript show alert window even the user has checked the 'Prevent this page from creating additional dialog' ?

No, there isn't.
Thank goodness.
(you could, however, fake it with a modal dialog--possibly jQuery UI would suit your needs)

The whole point of that checkbox is to prevent sites from continuously spamming the user with alert boxes, preventing them from accessing anything in their browser anymore, even switching tabs. If it were possible for a site to continue posting new alert messages after the user decided he doesn't want to see it anymore, the whole buisness of "Don't click this link" where you'd end up on an infinite loop of alerts if you did click it, would be made possible again. Nobody wants that.

Related

I want to make a popup which does not allows user to close browser until popup closes

I want to make popup which freezes the browser until the popup is closed. But I am stuck at a point since on closing the browser, it is asking the user to stay or leave but when a user clicks on leave it shuts down. I instead want a that when a user clicks the leave option it either reload the site or do nothing, also on doing the same for second time Chrome is giving alert to prevent any additional dialogue which I want to disable or it should do nothing. Until the popup is closed. So at last users should not be able to close their browser from a closing button of browser or by going back or replacing the URL. It should freeze until the requirement of the popup is fulfilled. Thank you and please help.
You can't force the users to stay on your site as the browser doesn't allow this (think of a malicious site forcing you to stay there). Your approach is probably the best you can do. Show a dialog that says something like. "Please wait while exiting..." or similar.
If you want to hide the "Block additional dialogs from this page" thing you can create your own dialog. Just a div with position: fixed and display: none and then onBeforeUnload show it with display: block.
Here is more on that: Stackoverflow.com
In that case you can use bootstrap popup:
like this:
https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_modal&stacked=h
and on the click event on close button you can add new alert or some other popup..
and closing this type of popup box cannot reflect other data..
It might helps you.!

window beforeunload is not working as expected in jquery

Basically what i am trying to do was, whenever a user tries to close the current tab(when he was on my site), i want to display a pop up with three choices about why he was leaving and want to store that choice some where
So i have written the following in main.js which will be loaded through entire site pages
$(document).ready(function() {
// Before closing the current tab, ask user for a reason
$(window).on('beforeunload', function(event){
$('#load_choices_up').click();
event.stopPropagation();
event.preventDefault();
debugger;
});
});
So i have three issues with the above jquery code
*.This code was executing even when i click another link on the same page(I mean if i navigate to another page from current page), but i only want this code to run when the current tab/page was closed(about to close) completely, but not when navigating to another page on my site
*. After this line $('#load_choices_up').click() was executed, a choices pop up was opening as expected, but immediately the default processing of browser(that is closing functionality) was not being stopped with two lines event.stopPropagation(); and event.preventDefault();, i mean these two methods of stopping the behaviour is not working and the browser is closed, but i want to do some processing based on user choices input and then based on that i will close tab.
*. When i used return "Why do you want to leave the page", instead of choices pop up, the browser was displaying different message based on browser type like "You have unsaved changes" in chrome, and some different message in firefox, instead of displaying my custom message
So finally, why event.stopPropagation(); and event.preventDefault(); are not working ? and why i can't able to display my custom message ?
You can't prevent someone from closing the browser. This is for obvious security reasons. Imagine a spam-website preventing you from closing the website while pumping you full of god knows what.
You can at most pull one function like an alert() or a prompt. After a user closes them, the tab will close either way.
beforeUnload is also extremely short-timed. You won't be able to run massive scripts with it, as the user would probably close the tap before any script would run properly. (I tried it with an ajax call, didn't work)
So, even if you're able to get the options you want in there, the moment a user chooses one of the options, you're not going to be able to save it anywhere. Your script will never make it that far.
You can customize the "are you sure?" message like so:
$(document).ready(function() {
window.onbeforeunload = function(e) {
return 'Dialog text here.';
};
});
but again, you can only change the text. It's a browser's native functionality, and you cannot change it.

Browser Tab Close Event for javascript or jquery

I have added a div which contains some survey questions which is initially hidden. Once the user closes the window or navigate away from the page, I need to popup the survey div to get the confirmation. I know there is a browser default confirm box method by using onbeforeunload event. But I need to popup the div rather than the browser default confirm box. Is there any way to do this? (or is there any way to interrupt the close event without even clicks on the "Stay on page" button found in the browser default confirm box?)
UPDATE : it seems we cannot do the action you are asking. There are some solutions to cover this in IE but overall its not possible. Ignore all the previous code.

Popup message when leaving page

I am looking to develop a small popup message which acts similar to the window.beforeunload function, to notify the user, that if they leave the current page, they will lose all of their data.
However the issue with the beforeunload event is it fires to often.
I would like to have the popup message fire only when a user closes the page, or clicks a link which takes them away from the current page, to ensure they are aware that their current action will result in the loss of the form data they have entered so far.
However beforeunload event goes further to fire when they refresh the page, which is not needed for this case, and also when the forum is submitted.
Could anyone advise me on the best way to develop this. I thought about using a basic confirm dialog and have it fire under the right circumstances, however is it possible to know if the user is refreshing the page, and if the forum is being submitted (without jQuery).
How can I have this dialog fire at the appropriate times?
Unfortunately, I don't think this is possible. The page unload events are very limited, for security reasons.
If you only want it to appear if the user added or changed formdata, why not check for changes in the data? If yes then return the question on beforeunload, if not do nothing.
Assuming that the form isn't too complicated, you could save form data by using Ajax call, which means there will not be a page reload. So, beforeunload will then behave as it was designed to.

input type="file" auto click

How do I automatically open the browse dialog of an input type="file" when the page first opens?
I don't think you should do this. If you've ever visited a MySpace page, you know how frustrating it can be when a web page activates things on its own when the page loads.
Don't violate how the UI is supposed to work, let the user ask for the dialog.
Besides, if the users instinctively closes it like a popup, and then realizes they needed it, it may not be obvious how they should get the dialog back. Then they will reload the page just to show the dialog again -- all frustrating things you could be avoiding.
That being said, I'm not sure why you want to do this in the first place. This is just my first reaction to what you're asking.
This is completely impossible in Firefox.
In other browsers, you can:
document.getElementById('inputId').click();
fire the click event on the button on document ready
$(document).ready(function() {
$("#buttonid").click();
});

Categories

Resources