I need to create a modal dialog on a webpage using javascript. Normally this would be easy as I could use something like jQueryUI or BlockUI, but the caveat here is that I'm not permitted to use jQuery, and I need to support IE9 quirks mode (ie no html5 doctype). I can't find anything online pertaining to what I need. Would anyone have suggestions? Thanks.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
- jQuery add and remove delay
Using
position:fixed
and this fiddle,
I have managed to overcome the limitations of the first answer
getting this demo. you basically need glass div with full screen and fixed position styling and nested scrollable content div.
You could also use
document.write
and then redirect to close the dialog.What about doing overlay with a div centered in the middle?
You can have div which you can hide (using javascript):
The CSS style for overlay can look like this:
Than you can use javascript to switch the visibility of the content in the overaly div:
More for example here: http://raventools.com/blog/create-a-modal-dialog-using-css-and-javascript/
ModaliseJS, lighter than
tomloprodModal
and compatible with any CSS.HTML : (omit modalise.css if you have your own design or using bootstrap)
Code :
I created a library called tomloprodModal that does what you need. It's a simple and configurable javascript library to create responsive and minimalist modal windows with no dependencies.
I hope it helps you.
Installation:
Just download and add the tomloprodModel.css and tomloprodModel.js to your website.
You can use bower too:
bower install tomloprodModal
or using npm:npm install tomloprodModal
Initialization:
Javascript:
Example of modal window:
Result:
Or, you can create the modal window without any HTML:
Documentation:
https://github.com/tomloprod/tomloprodModal
Demo:
http://codepen.io/tomloprod/pen/kkYxWY
I created a library called Msg that makes it easy to create modal windows. It has a lot of options and events to make your own different kinds of modal windows. Everything can be customized through css. It's also a single file, no need to import css files.
I have written some simple JavaScript functions for exactly this purpose, as well as a demo page to show you how to use them. You can view this at http://www.interbit.com/demos/modal.html.
The functions I've written are called MsgBox(), YesNo(), and YesNoCancel(). They do what their names imply.
To use them just make a copy of the JavaScript file at the link above, and include it in your HTML. Please do not just link to the file. Rather, make a copy of it, because I may change it or take it down at any time.
Samples:
I've also included a function called JavaScriptError() that takes a JavaScript Error object and formats it for display to the user, suitable for use in a try/catch block:
Here's the full listing of the code, as suggested by one of the commenters. You may include it in all your projects. I have some snarky comments about how I want you to give me credit, but really all I'm asking for is common courtesy. I don't really intend to sue anyone unless you steal the code and claim you wrote it.