Use javascript to open the modal dialog box of the sample code

  • 2020-03-30 01:20:37
  • OfStack

1. The standard approach


<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 
(' / / www.jb51.net ', '500 px', '400 px', 'no') "> Click < / span>  

Window. Open 
('openwin.html','newWin', 'modal=yes, width=200,height=200,resizable=no, scrollbars=no');  

3. How to automatically determine the browser


<input type="button" value=" Open the 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, modal dialogs hide the address bar, but not necessarily in other browsers

< img Alt = "" border = 0 border = 0 SRC =" / / files.jb51.net/file_images/article/201401/201401110934472.png "width = 626 height = 451 >

< img Alt = "" border = 0 border = 0 SRC =" / / files.jb51.net/file_images/article/201401/201401110934473.png "width = 630 height = 476 >

Note: in a Google browser, this mode is also disabled.

< img Alt = "" border = 0 border = 0 SRC =" / / files.jb51.net/file_images/article/201401/201401110934474.png "width = 1072 height = 780 >

< img Alt = "" border = 0 border = 0 SRC =" / / files.jb51.net/file_images/article/201401/201401110934475.png "width = 1075 height = 790 >

How does this work?


        /// displays the details of an order through a modal dialog, 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
The body1
{
      Background - color: # 999999;
      The filter: Alpha (Opacity = 40);
}

<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <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 + ";dialogHeight:" + height + ";scroll" + showScroll + ";");
        }
        function ShowOrderDetails(orderId) {
            var url = 'Details.aspx?orderID=' + orderId;
            $("body").addClass("body1");
            ShowDetailsDialog(url, '500px', '400px', 'no');
            $("body").removeClass("body1");
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <span style="cursor:pointer" onclick="ShowOrderDetails(11)" > Click on the </span>
    </div>
    </form>
</body>
</html>


Related articles: