Dynamically generated IFRAME, problem-solving analysis _javascript techniques when setting SRC

Source: Internet
Author: User
First look at the example:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "Content=" Tex t/html; Charset=utf-8 "/> <title> Untitled document </title> </pead> <body> <script language=" JavaScript " Type= "Text/javascript" > var IFR = document.createelement ("IFRAME"); Document.body.appendChild (IFR); IFR.SRC = "http://www.baidu.com"; </script> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]


This paragraph, ifr.src put after append, run, the surface is nothing, seemingly normal. But if you look at it with a grab tool, you'll find that when you refresh (F5 or refresh the button), you get one more request:

00:00:04.671 0.021 * Get aborted text/html http://www.baidu.com/

Although the status is aborted, this request is still sent to the server!

What if you put ifr.src before append? The problem is gone!

There are also similar:
After putting Ifr.frameborder = 0 on the append, the IFRAME can still look at the border. Before you put it in the append, the border is 0.
The ifr.scrolling = "No" After the append, does not work, put to append before it works.
The ifr.width,ifr.height has no effect on the front or the rear.


However, if you want to add a temporary parameter to the address of the IFRAME to achieve the effect of requesting a new page each time, put the ifr.src in the append before you go (refresh or F5)!

such as code:

<textarea id="runcode23705"><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "Content=" Tex t/html; Charset=utf-8 "/> <title> Untitled document </title> </pead> <body> <script language=" JavaScript " Type= "Text/javascript" > var IFR = document.createelement ("IFRAME"); Ifr.frameborder = 0; ifr.scrolling = "No"; IFR.SRC = "http://www.baidu.com?tmp=" + (new Date (). GetTime (). ToString (36)); Document.body.appendChild (IFR); Ifr.width = 500; Ifr.height = 500; </script> </body> </ptml></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

You can monitor, every time you refresh, that TMP is the same value! Unless you reload (not f5/refresh).
A different way? Use document.write to achieve? Can tell you, also not!

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.