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.