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/