To open a modal dialog box using JavaScript

Source: Internet
Author: User

1. The standard method

<script type="text/javascript">
function openWin(src, width, height, showScroll){
window.showModalDialog  (src,"","location:No;status:No;help:No;dialogWidth:"+width+";dialogHeight:"+height+";scroll:"+showScroll+";");
}
</script>

Example: <span style= "Cursor:pointer" onclick= "Openwin

(' http://www.deepteach.com ', ' 500px ', ' 400px ', ' no ') ' > click </span>

2. It is to be noted that Firefox does not support this feature, it supports the syntax is

window.open
(’openwin.html’,'newWin’, 'modal=yes, width=200,height=200,resizable=no, scrollbars=no’ );

3. How to automatically judge the browser

<input type="button" value="打开对话框" onclick="showDialog('#')"/>
<SCRIPT   LANGUAGE="JavaScript">
<!--
function   showDialog(url)
{
if(   document.all   ) //IE
{
feature="dialogWidth:300px;dialogHeight:200px;status:no;help:no";
window.showModalDialog(url,null,feature);
}
else
{
//modelessDialog可以将modal换成dialog=yes
feature ="width=300,height=200,menubar=no,toolbar=no,location=no,";
feature+="scrollbars=no,status=no,modal=yes";
window.open(url,null,feature);
}
}
//-->
</SCRIPT>

4. In IE, the modal dialog box hides the Address bar, while in other browsers it is not necessarily

"Note" In Google Browser, the effect of this mode will also be ineffective.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.