动态改变样式表的路径不工作在IE和Firefox [英] Dynamically changing stylesheet path not working in IE and Firefox

查看:91
本文介绍了动态改变样式表的路径不工作在IE和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()调用......这些都只是为了解决一个问题,即不是从一个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 ......无论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.

有什么奇怪的是,在Chrome浏览器它的伟大工程。 DOC负载在内容股利和样式表被设置为CSS和CSS应用到该页面。我可以用CSS页面和withing 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将加载,我可以看到样式表链接的 href属性得到改变为/ CSS +的getTime(),但同时,HTML负荷的CSS是的永远的应用于页面。我甚至可以改变商务部的内容,并更新,但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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆