Can I write HTML for Window.showModalDialog ()?

I use:

Window.showModalDialog(...) 

to open the dialog box

I want to show HTML code in this window, but I don't have a file. (Unable to use URL to visit)

how to show "hello world!" in this dialog box.

Can I do it?

+4
source share
2 answers

Interest Ask!

I am not an expert in modal dialogs, but I do not think that you can, because it is in the nature of a modal dialog to block any additional code from executing until the window is closed again.

I thought about using data: URI , which you could use as the first argument to showModalDialog instead of the usual URL:

  window.showModalDialog("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D" ....); 

but according to the MSDN page according to: URIs that will not be supported in Internet Explorer. (see the "Notes" section on the linked page)

It may work in Firefox: Learn more about data URIs in the Mozilla Developer Center

Update: Works in Firefox: JSFiddle , but, as expected, not in IE. You get only an empty window.

+3
source

Good question and answer. (+1)

I just thought I'd add that if you need to enter HTML into a modal dialog, you might need to study the Javascript library to execute it. I used Dojo " dijit.Dialog " several times with HTML, including images, form controls, etc. You can style it as you like, and it works well in a cross browser.

You can check out a few examples of using dijit.Dialog in DojoCampus .

Greetings.

0
source

All Articles