Two questions about the IE Modal Dialog Box

Source: Internet
Author: User
The modal dialog box opened by showModalDialog has many classic flaws. I will not talk about it here. I will only talk about several problems recently encountered and solutions.

Question 1. ShowModalDialog when you open an aspx page, if the page has been opened once before, the page in the cache will be automatically loaded without displaying the latest data.

There are two solutions:

(1) When opening the modal box, add a random parameter to the url to avoid page caching:

Var url = 'editflownode. aspx? FlowId = 0 & id = 2 & x = '+ Math. random ();
Var result = window. showModalDialog (url, '', 'status: no; help: no ;');

(2) In the Page_Load method of the asp.net page, set not to cache:

Protected void Page_Load (object sender, EventArgs e ){
Response. Expires = 0;
Response. Cache. SetNoStore ();
Response. AppendHeader ("Pragma", "no-cache ");
}

Question 2The content in the modal dialog box is different from the Script Loading Order, resulting in problems.

Origin: Consider the following page code

<! 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>
<Title> new document </title>
<Meta name = "generator" content = "editplus"/>
<Meta name = "author" content = ""/>
<Meta name = "keywords" content = ""/>
<Meta name = "description" content = ""/>
</Head>

<Body>
<Input id = "txt1">
<Script type = "text/javascript">
<! --
Alert (document. getElementById ('txt1'). offsetWidth );
// -->
</Script>
</Body>
</Html>

On this page, if you load data in a normal IE window, the message "155" is displayed, while in the modal dialog box, the value is "0 ". Why?

We noticed that when the normal window opens this page, when the alert dialog box is displayed, the entire page element is displayed normally. When the modal box is opened, after the alert dialog box is displayed, the background is indeed blank. The webpage content is displayed only after you click "OK.
It can be inferred that the order of the modal box and the ordinary page when parsing and executing HTML is different:

Normal page: Parse the elements in the body in sequence, and then draw the parsed elements. If you encounter a script, execute it immediately.

Modal Dialog Box: Parses the elements in the body in sequence, but does not immediately draw them. If you encounter a script, execute it immediately. After the body is loaded, draw the elements in sequence.

As the offsetWidth attribute is accessed in the above sample code, we can infer that this attribute must be automatically calculated after the element is drawn (render. As a result, the problem occurs.

This is because a bug occurs when I use a third-party control in the modal dialog box, after debugging, the root cause is that the control uses the common code mode to output its HTML. That is, after an HTML output, the initialization script is output immediately. (This issue deserves the attention of ASP. NET control developers.)

Fortunately, I have the source code of this control. Therefore, modifying the source code solves this problem. My solution is similar to this:

<! 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>
<Title> new document </title>
<Meta name = "generator" content = "editplus"/>
<Meta name = "author" content = ""/>
<Meta name = "keywords" content = ""/>
<Meta name = "description" content = ""/>
</Head>

<Body>
<Input id = "txt1">
<Script type = "text/javascript">
<! --
Var _ document_body_onload = document. body. onload;
Document. body. onload = function (){
// Perform initialization here
Alert (document. getElementById ('txt1'). offsetWidth );

If (_ document_body_onload & typeof (_ document_body_onload) = 'function ')
_ Document_body_onload ();
}
// -->
</Script>
</Body>
</Html>

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.