Set the background color of iframe and fill in iframe

Source: Internet
Author: User

When creating a custom pop-up layer a few days ago, iframe needs to be used for a translucent background. However, the problem is that iframe cannot directly set the background color, baidu and google found that most people set src for iframe to point to a target html page, which only sets the background color in the body. I always think this is not very good. First, the page cache in iframe is very serious, and it will be difficult to modify the background color in the future. Second, if the access address is random, it will lead to refresh every time the pop-up box is refreshed.

My method:

Copy to ClipboardReference: [www.bkjia.com] <iframe src = "javascript: document. write ('<body style = \ 'background-color: black \'> </body> ') "> </iframe>

 

In this way, we can not only set the background color of iframe, but also do a lot of things, such as sometimes placing a simple image in iframe and writing a few lines of words, there is no need to write another page to point to it.

The following is a complete example:

Copy to ClipboardReference: [www.bkjia.com] <Head>
<Script type = "text/javascript">
Function ggyy ()
{
Var code = ["Code. push ("<body style = 'color: Red; '> ");
Code. push (" ");
Code. push ("<span style = 'color: Red; '> This is the word in iframe </span> ");
Code. push ("</body> ");
Code. push ("Return code. join ("");
}
</Script>
</Head>
<Body>
<Iframe width = "700px" height = "400px" src = "javascript: parent. ggyy ()"> </iframe>
</Body>
</Html>

From: http://www.cnblogs.com/zhoukun921/

Related Article

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.