Insert javascript into CSS

Source: Internet
Author: User

Quirksmode site creators found an interesting technique. The background-image attribute in CSS can be inserted into Javascript. Unfortunately, only IE5/6 is supported Currently. (IE7 I have no conditional test)
Run code box
<Style type = "text/css">
# Test {
Border: 1px solid #000000;
Padding: 10px;
Background-image: url ('javascript: alert ("Have You Seen Me? ");')
} </Style>
<Div id = "test"> Display messages </div>
[Ctrl + A Select All tips: You can modify some code and then press run]
If Javascript is inserted in multiple different id selectors in CSS. only the id selector is called in the XHTML file. to run the Javascript code. without the id selector called, the code will not run.
As follows, we have defined two id selectors. test1 and test2. but test2. is not called in xhtml, so you can only see the javascript code in test1.
Run code box

The code is as follows: Copy code
<Style type = "text/css">
# Test1 {
Border: 1px solid #000000;
Padding: 10px;
Background-image: url ('javascript: alert ("Have You Seen Me? ");')
}
# Test2 {
Border: 1px solid #000000;
Padding: 10px;
Background-image: url ('javascript: alert ("You can't see me! ");')
} </Style>
<Div id = "test1"> Display messages </div>

[Ctrl + A Select All tips: You can modify some code and then press run]
In addition to displaying messages, the author tries to use this technique to generate random background images.
Background-image: url (javascript: document. write ('Pix/test' + (parseInt (Math. random () * 5)+1)'.gif '));
Unfortunately, after several attempts, this idea was eventually considered impossible. I tried it myself. A random background image cannot be generated. it only shows the background. and overwrite. the original content stops the browser and continues to explain the rest of the xhtml operation.

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.