IE11 won't apply CSS for <body> onload attribute selector |
IE11 won't apply CSS for <body> onload attribute selector |
Duodecimalist |
Oct 23 2014, 03:17 PM
Post
#1
|
Newbie Group: Members Posts: 11 Joined: 23-October 14 Member No.: 21,713 |
I have a Web page generated by a server. I can't easily change the template that generates the page, but I can apply CSS to the page. The CSS has to apply to other pages as well, but the page I need to style has an "onload" attribute on the <body> element, so I'm targeting that in my CSS. More specifically the opening tag is
CODE <body onload="dofocus();" onunload="mungeHistory();"> An example of the CSS is CODE body[onload="dofocus();"] { color: #001936; } IE (I'm using IE11) refuses to apply the style, but every other browser does. Well, that's not entirely true: IE will apply the style, but only after I've clicked somewhere on the page. I've tried CSS like CODE :root body[onload="dofocus();"] { color: #001936; } body[onload] { color: #001936; } * body[onload="dofocus();"] { color: #001936; } but nothing seems to get IE to apply the style except for a click on the page. I'd appreciate any thoughts on this problem. The live page is not accessible, but I've got a copy of it at a demo page. If you view it in IE, click anywhere outside the main content of the page to get IE to apply the style. If you click on elements within the content of the page, IE will apply the styles just for those elements. |
pandy |
Oct 23 2014, 03:58 PM
Post
#2
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
Don't have access to ie11 and can't test. So this is just a thought. Have you tried with just body[onload]?
|
Christian J |
Oct 23 2014, 04:22 PM
Post
#3
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
IE (I'm using IE11) refuses to apply the style, but every other browser does. Well, that's not entirely true: IE will apply the style, but only after I've clicked somewhere on the page. I made a simple test page, and IE9 (the newest one I got) supported the CSS. QUOTE The live page is not accessible, but I've got a copy of it at a demo page. If you view it in IE, click anywhere outside the main content of the page to get IE to apply the style. If you click on elements within the content of the page, IE will apply the styles just for those elements. What do you see in IE11 that shouldn't be there? Compared with Firefox 31, my IE9 doesn't display the background image, the footer font looks different, and the "checkout area" has a white background instead of yellow. Clicking in my IE9 made no difference. There's also a validator error (P element in HEAD section): http://validator.w3.org/check?uri=http://w.../sco/index.html |
Duodecimalist |
Oct 23 2014, 04:42 PM
Post
#4
|
Newbie Group: Members Posts: 11 Joined: 23-October 14 Member No.: 21,713 |
Don't have access to ie11 and can't test. So this is just a thought. Have you tried with just body[onload]? It may do the same thing in earlier versions of IE, too, but I only have IE11. Yes, I've tried all sorts of variations on body[onload]. I haven't played around yet to see whether it's a more general problem with IE not liking any attribute selector on the body element, though I can't imagine it would be. You never know with IE, though. |
pandy |
Oct 23 2014, 04:52 PM
Post
#5
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
What doctype is used? I found a note about IE not supporting attribute selectors when in quirks mode.
http://msdn.microsoft.com/en-us/library/ie...2(v=vs.85).aspx |
Duodecimalist |
Oct 23 2014, 05:14 PM
Post
#6
|
Newbie Group: Members Posts: 11 Joined: 23-October 14 Member No.: 21,713 |
IE (I'm using IE11) refuses to apply the style, but every other browser does. Well, that's not entirely true: IE will apply the style, but only after I've clicked somewhere on the page. I made a simple test page, and IE9 (the newest one I got) supported the CSS. I'll have to see if I can find a machine with IE9 on it to test. The person who will be using this said she has IE7, but I suspect she meant she's using IE on Windows 7. QUOTE The live page is not accessible, but I've got a copy of it at a demo page. If you view it in IE, click anywhere outside the main content of the page to get IE to apply the style. If you click on elements within the content of the page, IE will apply the styles just for those elements. What do you see in IE11 that shouldn't be there? Compared with Firefox 31, my IE9 doesn't display the background image, the footer font looks different, and the "checkout area" has a white background instead of yellow. Clicking in my IE9 made no difference. There's also a validator error (P element in HEAD section): http://validator.w3.org/check?uri=http://w.../sco/index.html It's mostly a matter of IE not showing styling that should be there. The background image and gradient aren't shown in IE, the yellow background on the card number box isn't shown, the layout is wrong, the institutional logo in the bottom right corner shouldn't be shown. Interestingly the styles that are applied to the unqualified body element are being rendered; it's just the styles for the body element qualified with the onload attribute that aren't getting styled. The validator error about the P element in the HEAD section is for some commented-out javascript. The page probably isn't completely valid HTML, but I have no control over it. |
Duodecimalist |
Oct 23 2014, 05:18 PM
Post
#7
|
Newbie Group: Members Posts: 11 Joined: 23-October 14 Member No.: 21,713 |
What doctype is used? I found a note about IE not supporting attribute selectors when in quirks mode. http://msdn.microsoft.com/en-us/library/ie...2(v=vs.85).aspx I double checked the live page and it's being served as <!DOCTYPE html>, so that shouldn't be the problem. |
Christian J |
Oct 23 2014, 05:30 PM
Post
#8
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
I'll have to see if I can find a machine with IE9 on it to test. The person who will be using this said she has IE7, but I suspect she meant she's using IE on Windows 7. Can IE11 emulate earlier IE versions (press the F12 key to open its developer tools)? Otherwise you could always download http://www.my-debugbar.com/wiki/IETester/HomePage which use to give accurate rendering of earlier versions. QUOTE It's mostly a matter of IE not showing styling that should be there. The background image and gradient aren't shown in IE The above may not be supported by IE9, even though my IE9 does support onload as an attribute selector. I haven't examined the other styling. QUOTE The validator error about the P element in the HEAD section is for some commented-out javascript. No, it's the P inside this NOSCRIPT element: CODE <noscript><p><img src="http://piwik.ptfs-europe.com/piwik.php?idsite=6" style="border:0" alt="" /></p></noscript> Why not make a minimal test page somewhere else (e.g. on your local computer)? Then you can test if IE11 supports the attribute selector while ruling out other error sources. You can also make sure IE11 isn't confused by the validator error or any of the jQuery/javascript on the page. |
Frederiek |
Oct 24 2014, 03:15 AM
Post
#9
|
Programming Fanatic Group: Members Posts: 5,146 Joined: 23-August 06 From: Europe Member No.: 9 |
IE 7+ should support the attribute selector:
http://caniuse.com/#feat=css-sel3 http://www.quirksmode.org/css/selectors/ |
Duodecimalist |
Oct 24 2014, 10:05 AM
Post
#10
|
Newbie Group: Members Posts: 11 Joined: 23-October 14 Member No.: 21,713 |
It's looking to me like this is a bug in IE. I've got three pages with a lot of extraneous HTML and CSS removed or commented out. The HTML and CSS validate. In the second and third versions, I added an ID to the BODY tag.
http://www3.nd.edu/~fboze/sco/simple.html Selector in the form of -- body[onload="dofocus();"] CSS is not applied in IE11 http://www3.nd.edu/~fboze/sco/simple2.html Selector in the form of -- body#testid CSS is applied in IE11 http://www3.nd.edu/~fboze/sco/simple3.html Selector in the form of -- body[id="testid"] CSS is applied in IE11 I thought maybe IE was having trouble in general with attribute selectors on the BODY tag, so I tried both forms of expressing the ID. The only one that IE has trouble with is the "onload" attribute. The one thing that's changed is that on the simplified page simple.html, IE won't render the CSS even if I click on the page, unlike it previously did. However, if I open the Developer Tools (F12), and click on the elements in the DOM Explorer pane, the CSS will start to apply to each element I click on. |
Christian J |
Oct 24 2014, 01:21 PM
Post
#11
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
That's still a pretty complex stylesheet, I was thinking of something very basic to test the selector, like this test page:
CODE <!doctype html> <title>test</title> <style type="text/css" media="screen"> body[onload="dofocus();"] { color: blue; background: pink; } </style> </head> <body onload="dofocus();" onunload="mungeHistory();"> some text </body> </html> Or you could simply remove content until you find the bug. While I did that, I noticed that both the large background photo: CODE background: linear-gradient(to right, rgba(255,255,255,0) 0%,rgba(255,255,255,0) 25%,rgba(255,255,255,0.7) 40%,rgba(255,255,255,0.7) 100%), url("https://www3.nd.edu/~fboze/2012%20London%20Scenic%203_ab.jpg"); and the yellow box: CODE background: linear-gradient(to bottom, #fef8d3 0%, #ffec91 9%, #ffed87 89%, #f9dc00 100%) repeat scroll 0 0 rgba(0, 0, 0, 0); use CSS3 background linear-gradient values, that at least IE9 does not support. Don't know about IE11, but try replacing them with simpler CSS just to make sure. Ditto for viewport units like this one: CODE max-width: 100vw; max-height: 100vh; |
Duodecimalist |
Oct 24 2014, 01:43 PM
Post
#12
|
Newbie Group: Members Posts: 11 Joined: 23-October 14 Member No.: 21,713 |
IE11 should support all of the CSS in my stylesheet. It renders all the CSS if I target something other than the ONLOAD attribute on the BODY tag.
I've reduced the CSS and HTML even further as you suggested, and I'm still seeing the same problem in IE11. I find it interesting that IE will apply the CSS in the Developer Tools as I click on the elements, but not when the page loads. IE must handle the ONLOAD attribute differently than other attributes somehow. http://www3.nd.edu/~fboze/sco/simple4.html |
Christian J |
Oct 24 2014, 02:04 PM
Post
#13
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
I've reduced the CSS and HTML even further as you suggested, and I'm still seeing the same problem in IE11. I find it interesting that IE will apply the CSS in the Developer Tools as I click on the elements, but not when the page loads. IE must handle the ONLOAD attribute differently than other attributes somehow. http://www3.nd.edu/~fboze/sco/simple4.html FWIW, that page works in IE9... QUOTE IE must handle the ONLOAD attribute differently than other attributes somehow. Maybe IE11 confuses it with its old "CSS expressions", but that seems like a long shot. I also recall some browser could run actual javascript in STYLE elements (against all common sense), but I can't remember which one (this was many years ago). |
Frederiek |
Oct 24 2014, 04:37 PM
Post
#14
|
Programming Fanatic Group: Members Posts: 5,146 Joined: 23-August 06 From: Europe Member No.: 9 |
QUOTE Maybe IE11 confuses it with its old "CSS expressions", but that seems like a long shot. Maybe because onload is a javascript function rather than a attribute in the sense of CSS attribute selectors. QUOTE I also recall some browser could run actual javascript in STYLE elements (against all common sense), but I can't remember which one (this was many years ago). Sounds strange to me. All I can find is how to set/change CSS styling with javascript. Let me know if you recall. |
Christian J |
Oct 24 2014, 04:51 PM
Post
#15
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
QUOTE I also recall some browser could run actual javascript in STYLE elements (against all common sense), but I can't remember which one (this was many years ago). Sounds strange to me. All I can find is how to set/change CSS styling with javascript. Let me know if you recall. I think I mentioned it on this forum, perhaps something like CODE <style> alert('foo'); </style> <script> body {color: red;} </script> |
pandy |
Oct 24 2014, 05:45 PM
Post
#16
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
|
Christian J |
Oct 24 2014, 06:27 PM
Post
#17
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
I find it interesting that IE will apply the CSS in the Developer Tools as I click on the elements, but not when the page loads. Not sure I understood the above, how does Developer Tools affect things? BTW make sure your IE11 copy is not emulating an older IE version (in Developer Tools). Also check that you don't use any browser extension that interferes with the page's styling or DOM tree somehow (not sure how extensions work in IE). Have you tested IE11 on some other PC? |
Christian J |
Oct 24 2014, 06:30 PM
Post
#18
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
|
Duodecimalist |
Oct 24 2014, 10:35 PM
Post
#19
|
Newbie Group: Members Posts: 11 Joined: 23-October 14 Member No.: 21,713 |
I find it interesting that IE will apply the CSS in the Developer Tools as I click on the elements, but not when the page loads. Not sure I understood the above, how does Developer Tools affect things? BTW make sure your IE11 copy is not emulating an older IE version (in Developer Tools). Also check that you don't use any browser extension that interferes with the page's styling or DOM tree somehow (not sure how extensions work in IE). Have you tested IE11 on some other PC? So far, Developer Tools is the only way I've found to get the CSS to render. If I load this page http://www3.nd.edu/~fboze/sco/simple5.html in IE11, the CSS is ignored. Black text on a white background instead of blue text on a pink background. If I open Developer Tools, various things will cause the CSS to render in the page. If I switch from Edge (IE11) mode to IE10 mode, the CSS renders. If I switch back to Edge mode, the CSS remains rendered. On my office PC (but not my home PC) if I click on a P element in the DOM Explorer, the CSS for that element is rendered in the page. If I close IE, then open it again and load the page, no CSS is rendered until I once again open Developer Tools and change the mode, etc. I'm using IE11 on two 64-bit machines with pretty much the same results. They're not configured to emulate any other version of IE. I never use IE except to occasionally test a page I'm working on, so I've never added any extensions and all the configuration options are as they were when the OS was first installed. I'll just have to figure some way of styling that page without targeting the ONLOAD attribute. It's too bad I can't easily change the HTML, then I could add an ID attribute to the BODY and target that. |
Christian J |
Oct 25 2014, 05:33 AM
Post
#20
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
Can you edit any of the external javascript files? If so you might use that to add an ID for that particular web page's URL.
|
Lo-Fi Version | Time is now: 25th April 2024 - 10:41 AM |