Use JavaScript to open modal dialog box (sample code) _javascript Tips

Source: Internet
Author: User

1. The standard method

Copy Code code as follows:

<script type= "Text/javascript" >
function Openwin (src, width, height, showscroll) {
window.showModalDialog (SRC, "", "Location:no;status:no;help:no;dialogwidth:" +width+ ";d ialogheight:" +height+ "; Scroll: "+showscroll+"; ");
}
</script>

Example: <span style= "Cursor:pointer" onclick= "Openwin
(' http://www.jb51.net ', ' 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

Copy Code code as follows:

<input type= button value= Open dialog box "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 can replace modal with 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.

5. Generally in the pop-up dialog box, we all want the background of the entire parent page to become a translucent color, so that users can see the following is not accessible

When you close the dialog box and then you want to restore

How did this happen?

Copy Code code as follows:

Displays the details of an order through a modal dialog box, and the screen changes color
function Showorderdetails (orderId) {
var url = "details.aspx?orderid=" + OrderID;

$ ("Body"). CSS ("filter", "Alpha (opacity=20)");
Filter:alpha (OPACITY=50)

$ ("Body"). AddClass ("body1");

Showdetailsdialog (URL, "600px", "400px", "yes");

$ ("Body"). Removeclass ("body1");
}


In addition, there is a style sheet definition
. body1
{
Background-color: #999999;
Filter:alpha (OPACITY=40);
}
Copy Code code as follows:

<%@ Page language= "C #" autoeventwireup= "true" codebehind= "WebForm1.aspx.cs" inherits= "Webapplication1.webform1"% >

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

    < Title></title>
    <style type= "text/css"
    body1{
        Background-color: #999999;
        Filter:alpha (opacity=40);
   }
    </style>
    <script src= "jquery.js" type= "Text/javascript" > </script>
    <script type= "Text/javascript"
         function Showdetailsdialog (src, width, height, showscroll) {
             window.showmodaldialog (SRC, "", "Location:no;status:no;help:no;dialogwidth:" + width + ";d ialogheight:" + height + "; scroll" + Showscroll + ";");
       }

function Showorderdetails (orderId) {
var url = ' details.aspx?orderid= ' + OrderID;
$ ("Body"). AddClass ("body1");
Showdetailsdialog (URL, ' 500px ', ' 400px ', ' no ');
$ ("Body"). Removeclass ("body1");
}
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<span style= "Cursor:pointer" onclick= "Showorderdetails (one)" > click </span>
</div>
</form>
</body>

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.