How does stackoverflow create the modal dialog window? [duplicate] - javascript

This question already has answers here:
Modal Dialog without jQuery
(7 answers)
javascript to check when the browser window is closed
(5 answers)
Closed 7 years ago.
When I edit a page and try to leave it I get a dialog box that appears and asks me if I want to:
Leave this Page or Stay on this Page
The dialog blocks me from doing anything until I have answered.
In Javascript the only similar thing I see is window.confirm(message) which gives and OK and Cancel button.
So is there another way in Javascript that I can create a dialog that I don't know about? Please note that I want to create a dialog at any time and I am not interested in knowing when the page closes so this is not a duplicate of the question identified by Zeta.

What happens here, is not an alert() or confirm() or prompt() of any sort.
Write a function for the window.onbeforeunload event handler, load up the parameter with a function passing a message...
➪ ➪ ➪ stackoverflow.com/a/1119324/444255
What it generates is a special native dialog by your browser. (You can´t inspect it with devTools, it's not made from HTML... ok, alerts are neither.)
You can't get the same dialog for other purposes. (If it was possible, the advertising industry would habe let us known long ago ;-)
You can only 'block' either with ugly alert's and it's siblings, or by putting a shim over your page (to prevent clicks) and a html-made dialog on top. Which should stop other interactions with your page, but of course not navigating away.

JavaScript doesn't have a built in modal, only alert, confirm and prompt. Many libraries have made their own modals, Bootstrap and jQueryUI for example.

Your question isn't quite clear. What I understand is that you're interested in the available models.
window.alert() gives you the chance to send a notification to the user.
window.confirm() gives a popup with an Ok and a Cancel button.
window.prompt() gives a popup in which the user can insert text.
http://www.w3schools.com/js/js_popup.asp

Related

Display firefox extension popup programmatically

I'm developing a Firefox extension and I've been looking for a way to display it automatically (with JavaScript) under certain conditions, as if the user had clicked on the icon.
I know it is possible because some extensions already do it (like Wanteeed, see image below)
I have my javascript getting all the informations that I want, I know when my condition is okay the only thing that I need now is a way to make my little extension's 'popup' magically appear
I've looked for answers as I could, I hope that I didn't miss an already existing post, sorry if I did and thank you very much for your answers !
Are you using the latest WebExtensions format? If so, then you can't just open the popup page programmatically, this is for security reasons. From the MDN web docs:
When the user clicks the button, the popup is shown. When the user clicks anywhere outside the popup, the popup is closed. The popup can be closed programmatically by calling window.close() from a script running in the popup. However, you can't open the popup programmatically from an extension's JavaScript: it can only be opened in response to a user action.
An alternative is to use content scripts to append a position:fixed div to the current page, and then to style it with CSS to match the popup style. This is probably what the extension you referenced is doing.

Scripts not running in FF and Chrome

I am using javascript alert message to show validation messages. In Firefox and Chrome first time working fine,second time for same alert same its asking message like "Prevent this page from creating additional dialogs" with check box. After select that check box, Next time button click scripts not executing. How to block that message?
Use a JavaScript Modal popup! eg. JQuery UI Modal Popup
This is a browser matter, so you as a developer cant do anything with that behavior.
Here is a similar question
already answered here
unfortunately you can't be sure that user has his browser settings with javascript alerts popup on ( that called with 'alert('...') function').
You should use javascript dialog plygin instead.
For example:
http://fancybox.net/
its a browser property for the client,if he doesnt want to view these alerts. you cant remove that check box and message.
if this message is shown then what the problem, leave it for the user.
why you want to force him to view these alerts,
it must be user's wish to see or not see these alerts.
for better user experience and for your purpose you can use fancybox or facebox
fancy box fiddler check this http://jsfiddle.net/BJNYr/

How to alert user to not close the window while he has submitted the form to process? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Javascript To Get An Alert When Closing The Browser Window
I am having a site on which users are visiting and uploading video, in that i am having a problem that users are closing the browsers or navigating from the page without letting the upload process to complete, i want to show a alert box to the user to not close the window or not to navigate from the page when uploading process is going on, i tried it through window.unload but it will not work for me because as the uploading process is going on the page will be submitted so that event will always be called, please tell me the way to show the alert box to users on window close or they navigate from the page.
Thanks in advance,
Ravinder Singh
Did you try to use:
window.onbeforeunload

how to throw an alert saying " please turn off the pop up blocker" [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I detect if a browser is blocking a popup?
hi iam trying to open a child window with disabled toolbar.......
how to check whether the child window is opened or not and then display this alert??
can someone help with code.........
When you create a new window using window.open(), it returns a handle to the (theoretically) opened window. You can then test that handle to determine whether the window is open:
var child = window.open("mypopup.html");
// some popup blockers prevent the window from being created (!child) and
// others just close them before they're displayed (child.closed)
if (!child || child.closed) {
// tell the user to turn off their popup blocker
}
Popups are very intrusive, however, and you should consider trying to display the "popup" information within the page. In particular, have a look at "dialog" scripts. If you're using jQuery, a very nice Dialog widget is included in the jQuery UI library.
I think, if popups are blocked, window.open() will return a null, not a window object. You can read it in an MSDN article:
If you are not sure whether a pop-up
window is blocked, check your
functions that return a window object.
You can tell if a pop-up window has
been blocked if these functions return
null. In particular, you need to check
the value of window.open to avoid
script errors when your pop-up windows
are blocked.
Also, this will give you some hints about detection of popup blockers: http://www.visitor-stats.com/articles/detect-popup-blocker.php
You need to give us the Javascript you are using so that we can help. You will need an 'if' statement.
Display alerts like this in javascript:
alert('Please turn off your pop-up blocker');

To Disable The BackButton Of Browser Window Using Javascript [duplicate]

This question already has answers here:
Closed 13 years ago.
Possible Duplicate:
Disabling Back button on the browser
Hi Guys,
I need to disable the backbutton of browser window.When I click on backbutton,I need to show one message using alert or other means.Any one can help me
you can't make the user stay on your page, but you can give a yes/no prompt first, though.
read around Is there a way to determine that the browser window was closed?
Short answer: don't.
There's something wrong with the design if you have to do this.
I HATE it when web pages do this.
I'd suggest another way of approaching the usability of your page first.

Categories