I know this has probably been asked before, but here goes: I have a web application that needs to generate modal dialogs. alert
, confirm
, and prompt
are too simple and ugly, and that modal window function...it's a long story. I can't use it. So, I'm going to create the modal box using DOM functions and CSS. However, I need to put quite a lot of content into the dialog, and I'm wondering what the best way to do this is. Putting the HTML into a string and using innerHTML
is unwieldy. I could use the DOM, but that's annoying and takes too much time to code. I know I can use a script with a weird type tag (something like x-random/x-htmlstuff
) and then copy it's content to the innerHTML
, but is there a better, more "official" way to do this?
The write() method writes directly to an open (HTML) document stream.
To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.
JavaScript can "display" data in different ways: Writing into an HTML element, using innerHTML . Writing into the HTML output using document.write() .
JavaScript in <head> or <body> You can place any number of scripts in an HTML document. Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.
if the layout of the modals are static, just put them into the HTML of the page. Use CSS to set them to display: none
when the page is displayed normally. When you want to display the model, use
document.getElementById('modal-id').style.display = 'block';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With