开发者

Can I write HTML code to Window.showModalDialog()?

I use :

Window.showModalDialog(...)

to open a dialog window,

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

like show "hello world!" in this dialog window.

C开发者_如何学Can I do it?


Interesting question!

I'm not an expert in modal dialogs, but I don't think you can, because it's in the nature of a modal dialog to block any further code from being executed until the window is closed again.

I thought about using a data: URI that you could use as the first argument to showModalDialog instead of a normal URL:

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

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

It might work in Firefox, though: More on data URIs at Mozilla Developer Central

Update: It works in Firefox: JSFiddle but, as expected, not in IE. You only get a blank window there.


Good question and answer. (+1)

I just thought I'd add, that if you do need to enter HTML into a modal dialog, you may want to look into using a Javascript library to accomplish it. I've used Dojo's "dijit.Dialog" several times with HTML, including images, form controls etc... You can style it however you like, and it works well cross-browser.

You can check out a few example of dijit.Dialog's use over at DojoCampus.

Cheers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜