动态更改样式表路径在IE和Firefox中不起作用 [英] Dynamically changing stylesheet path not working in IE and Firefox
问题描述
我有以下文件:
<html>
<head>
<title></title>
<link rel="css" type="text/css" href="/empty.css" title="css" />
<script type="text/javascript" src="/Prototype"></script>
<script type="text/javascript">
function load_content()
{
var d = new Date();
new Ajax.PeriodicalUpdater('content', '/DOC?'+d.getTime(),
{
method: 'post',
frequency: 5,
onSuccess: function(transport) {
for(i=0; (a = document.getElementsByTagName('link')[i]); i++)
{
if(a.getAttribute('rel') == 'css' && a.getAttribute("type") == 'text/css')
{
a.href = '/CSS?'+d.getTime();
}
}
}
});
}
</script>
</head>
<body>
<div id="content"></div>
<script type="text/javascript">
load_content();
</script>
</body>
</html>
注意:忽略d.getTime()调用...这些只是为了解决问题IE不会从AJAX调用加载新页面,因为它的缓存方案过于激进。
Note: Ignore the d.getTime() calls...these are just to get around an issue with IE not loading a new page from an AJAX call because it's caching scheme is too aggressive.
基本上,当它在/ DOC重新加载文件时,应该是将当前样式表设置为/ CSS ... / CSS ... DOC和CSS中的文件,并不断更改。
Basically, when it reloads the file at /DOC, it is supposed to be setting the current stylesheet to the file at /CSS... both DOC and CSS and constantly changing.
很奇怪的是, DOC在contentdiv中加载,样式表设置为CSS,并且css应用于页面。我可以改变CSS页面和5秒,当页面刷新时,CSS也将刷新。
What's weird is that in Chrome it works great. DOC loads up in the "content" div and the stylesheet gets set to CSS and that css is applied to the page. I can change with CSS page and withing 5 seconds, when the page is refreshed, the CSS will be refreshed as well.
但在IE和Firefox,HTML将加载我可以看到样式表链接 IS 的href属性更改为/ CSS + getTime(),但是在HTML加载时,css将永远不会应用到页面。我甚至可以更改DOC的内容,它的更新,但css永远不会应用。
But in IE and Firefox, the HTML will load and I can see that the href attribute of the stylesheet link IS getting changed to "/CSS + getTime()" but, while the HTML loads, the css is never applied to the page. I can even change the content of DOC and it updates, but the css is never even applied. It just stays a style-free page.
Firefox和IE不支持以这种方式更改样式表引用吗?
有更好的方法吗?
Does Firefox and IE not support changing the style sheet reference in this way? Is there a better way to do this?
推荐答案
不要在单个链接中更改工作表,替代样式表。请参阅使用备用样式表的链接:
Rather than changing the sheet in a single link, try using alternate style sheets. See this link on using alternate style sheets:
http://www.alistapart.com/articles/alternate/
这篇关于动态更改样式表路径在IE和Firefox中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!