ShowModalDialog and Showmodelessdialog_javascript Skills

Source: Internet
Author: User
On the use of ShowModalDialog and showModelessDialog, a B/ s structure of the project with window.open pop-up window by some advertising interception tool to intercept, no way can only use ShowModalDialog to solve the problem, but showmodaldialog this method is bad is the page transfer value too troublesome (the value of two methods), But there is no other way to solve this interception problem, only use this. The code is written in two. But when debugging code to find a problem, with ShowModalDialog pop-up window content is the first time to access the content of the page, the beginning of the suspect is the form call page cache, and finally through the single step tracking debugging also proved that the problem is indeed read page cache , which shows that it is best to add Response.Expires = 0 to the Page_Load event when using ShowModalDialog and showModelessDialog as pop-up forms in asp.net.
Response.Cache.SetNoStore ();
Response.appendheader ("Pragma", "No-cache");
To clear the cache. The use of Asp,php,js,vbscript test using the ShowModalDialog method does not appear to need to clear the cache, you can rest assured that the use of the ShowModalDialog when you can see the following I found a detailed introduction

ShowModalDialog and showModelessDialog use experience

What's the difference between ShowModalDialog and showModelessDialog?
ShowModalDialog: The input focus is always maintained when it is opened. The user cannot switch to the main window unless the dialog box is closed. Similar to the running effect of alert.
showModelessDialog: After being opened, the user can randomly switch the input focus. Has no effect on the main window (at most, it is blocked.) :P)

Second, how to let the ShowModalDialog and showmodelessdialog hyperlinks do not eject a new window?
Add <base target= "_self" to the Web page you've opened. > This sentence is usually placed between
Third, how to refresh the contents of ShowModalDialog and showModelessDialog?
In ShowModalDialog and showModelessDialog can not press F5 refresh, and can not pop-up menu. This can only depend on JavaScript, and here's the relevant code:

<body onkeydown= "if (event.keycode==116) {Reload.click ()}" >
<a id= "Reload" href= "filename.htm" style= "Display:none" >reload...</a>

Replace the filename.htm with the name of the Web page and put it on your open Web page, press F5 to refresh, note that this should be matched <base target= "_self" > Use, or you press the F5 will pop up a new window.

Note: If you want to automatically refresh when you visit, you can set a record variable on the page being opened, when the modal window is opened, the variable to 1, and then use the method to refresh the modal window, when the window is closed, the variable to 0.

How to use JavaScript to turn off ShowModalDialog (or showmodelessdialog) open windows.
<input type= "button" value= "Close" onclick= "Window.close ()" >
Also need to cooperate with <base target= "_self", otherwise will open a new IE window, and then turn off.

V. ShowModalDialog and showModelessDialog data transfer skills.
Example:
Now you need to read or set a variable in a showmodaldialog (or showModelessDialog) var_name

General mode of delivery:
window.showModalDialog ("filename.htm", Var_name)
Passing Var_name variables
When ShowModalDialog (or showModelessDialog) reads and sets:
Alert (window.dialogarguments)//Read Var_name variable
window.dialogarguments= "Oyiboy"//Set var_name variable
This is a way to be satisfied, but when you want to operate var_name and then manipulate the second var_id? can no longer operate. This is the limitation of this way of passing.
    
The following are the delivery methods I recommend:
window.showModalDialog ("filename.htm", window)
Just pass the window object of the main window straight, regardless of the variable you want to manipulate
When ShowModalDialog (or showModelessDialog) reads and sets:
Alert (Window.dialogArguments.var_name)//Read Var_name variable
Window.dialogarguments.var_name= "Oyiboy"//Set var_name variable

And I can also manipulate var_id variables.
Alert (WINDOW.DIALOGARGUMENTS.VAR_ID)//Read var_id variable
Window.dialogarguments.var_id= "001"//Set var_id variable

You can also manipulate any object in the main window, such as an element in a Form object.
Window.dialogarguments.form1.index1.value= "This is the value of setting the INDEX1 element"

Six, multiple showmodelessdialog of mutual operation.

The main function of the following code is to move a showmodelessdialog position in a showmodelessdialog.

Part of the main file JS code.
var s1=showmodelessdialog (' control. htm ', window, ' dialogtop:1px;dialogleft:1px ')//Open Control window
var s2=showmodelessdialog (' About:blank ', window, "dialogtop:200px;dialogleft:300px")//Open controlled window

A partial code that controls. htm.
<script>
The operation position data, because the window position data is "xxxpx" the way, therefore needs such a special operation function.
function CountNumber (A_STRNUMBER,A_STRWHATDO)
{
A_strnumber=a_strnumber.replace (' px ', ')
A_strnumber-=0
Switch (A_STRWHATDO)
{
Case "-": a_strnumber-=10;break;
Case "+": a_strnumber+=10;break;
}
return a_strnumber + "px"
}
</script>
<input type= "button" onclick= "Window.dialogarguments.s2.dialogtop=countnumber" ( Window.dialogArguments.s2.dialogTop, '-') ' value= ' Move Up >
<input type= "button" onclick= "Window.dialogarguments.s2.dialogleft=countnumber" ( Window.dialogArguments.s2.dialogLeft, '-') "value=" left >
<input type= "button" onclick= "Window.dialogarguments.s2.dialogleft=countnumber" ( Window.dialogArguments.s2.dialogLeft, ' + ') ' value= ' Move right >
<input type= "button" onclick= "Window.dialogarguments.s2.dialogtop=countnumber" ( Window.dialogArguments.s2.dialogTop, ' + ') ' value= Move Down >

The above key parts are:
Window naming mode: var s1=showmodelessdialog (' control. htm ', window, "dialogtop:1px;dialogleft:1px")
Variable access mode: Window.dialogArguments.s2.dialogTop

This example is only the reality of the position between showModelessDialog and showModelessDialog function, through this principle, in showModelessDialog control each other's display page, transfer variables and data. It depends on how you play.

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.