Nivo 滑块在 IE8 中不工作

发布于 2024-12-09 11:43:25 字数 2351 浏览 0 评论 0原文

我在公司网站上的 jquery nivo slider 遇到一些问题。

首先,该网站由一家提供内部 cms 的公司托管,我们无法更改任何内容。这就是为什么我没有任何权限在 Head-Tag 中加载任何内容,并且无法上传该服务器上除图像之外的任何文件,

所以我找到了一个 Javascript,它随后在 head 中加载 CSS 文件。好吧,所有这些都可以在每个浏览器(Chrome、FF、IE6、IE9)中正常工作,除了 IE8,NivoSlider 仅加载第一个图像,不显示标题,不导航。

我不知道为什么会这样做,因为如果我在本地执行代码(如下所示),它就会起作用(所有文件也都存储在本地)。

<script type="text/javascript" src="slider/scripts/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="slider/scripts/jquery.nivo.slider.js"></script>
<script type="text/javascript">
  function loadjscssfile(filename, filetype){
     if (filetype=="js"){ //if filename is a external JavaScript file
      var fileref=document.createElement('script')
      fileref.setAttribute("type","text/javascript")
      fileref.setAttribute("src", filename)
     }
     else if (filetype=="css"){ //if filename is an external CSS file
      var fileref=document.createElement("link")
      fileref.setAttribute("rel", "stylesheet")
      fileref.setAttribute("type", "text/css")
      fileref.setAttribute("href", filename)
     }
     if (typeof fileref!="undefined") {
      document.getElementsByTagName("head")[0].appendChild(fileref)
    }
    }

  function toggle() {
    var slider = document.getElementById("slider");
    slider.style.display = "block";
  }

    $(window).load(

    function() {
            loadjscssfile("slider/css/nivo-default.css", "css");
            loadjscssfile("slider/css/nivo-slider.css", "css");
            toggle();
            $('#slider').nivoSlider();

    }
    );

</script>

Hoster 使用 Prototype JS Framework 作为他们的 CMS,所以我想这可能会造成某种干扰。实际上,如果我在 IE8 中打开 Devtools,我会在 Hoster 提供的 Prototype.js 文件中显示一些错误

var nodes = $(element).getElementsByTagName('*');
className = ' ' + className + ' ';

for (var i = 0, child, cn; child = nodes[i]; i++) {
  if (child.className && (cn = ' ' + child.className + ' ') && (cn.include(className) ||
      (classNames && classNames.all(function(name) {
        return !name.toString().blank() && cn.include(' ' + name + ' ');
      }))))
    elements.push(Element.extend(child));
}

,它不喜欢这些行,它会说类似(翻译自德语)“该对象不支持此值或方法》

你可以看原主页和代码XXX,自己尝试一下。我希望你能帮助我解决我的问题。

I am encountering some issues with the jquery nivo slider on my companies website.

First of all, the website is hosted by an company who provided a inhouse cms where we can't change anything. That's why I don't have any permissons to load anything in the Head-Tag and can't upload any files except Images on that server

So I found a Javascript which loads CSS files in the head afterwards. Well all of this works properly in every browser (Chrome, FF, IE6, IE9) except IE8 the NivoSlider loads only the first Image, shows no caption, no navigation.

I have no clue why it does that because if I execute the code (shown below) locally it works (all files are stored locally too).

<script type="text/javascript" src="slider/scripts/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="slider/scripts/jquery.nivo.slider.js"></script>
<script type="text/javascript">
  function loadjscssfile(filename, filetype){
     if (filetype=="js"){ //if filename is a external JavaScript file
      var fileref=document.createElement('script')
      fileref.setAttribute("type","text/javascript")
      fileref.setAttribute("src", filename)
     }
     else if (filetype=="css"){ //if filename is an external CSS file
      var fileref=document.createElement("link")
      fileref.setAttribute("rel", "stylesheet")
      fileref.setAttribute("type", "text/css")
      fileref.setAttribute("href", filename)
     }
     if (typeof fileref!="undefined") {
      document.getElementsByTagName("head")[0].appendChild(fileref)
    }
    }

  function toggle() {
    var slider = document.getElementById("slider");
    slider.style.display = "block";
  }

    $(window).load(

    function() {
            loadjscssfile("slider/css/nivo-default.css", "css");
            loadjscssfile("slider/css/nivo-slider.css", "css");
            toggle();
            $('#slider').nivoSlider();

    }
    );

</script>

The Hoster uses Prototype JS Framework for their CMS, so I thought maybe that causes some kind interference. Actually if I open the Devtools in IE8 I shows me some errors in the Prototype.js file provided by the Hoster

var nodes = $(element).getElementsByTagName('*');
className = ' ' + className + ' ';

for (var i = 0, child, cn; child = nodes[i]; i++) {
  if (child.className && (cn = ' ' + child.className + ' ') && (cn.include(className) ||
      (classNames && classNames.all(function(name) {
        return !name.toString().blank() && cn.include(' ' + name + ' ');
      }))))
    elements.push(Element.extend(child));
}

It doesn't like these lines, it says something like (translated from german) "the object does not support this value or the method"

You can see the original homepage and code XXX and try it out for yourself. I hope you can help me with my issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑叹一世浮沉 2024-12-16 11:43:25

检查 Chrome 的开发者工具后,我发现的唯一问题是:

var nivo-child = $(this);

变量名称中不能有破折号,请将其更改为 nivo_childnivoChild


要修复第二个错误,您需要使用 jQuery.noConflict()

Checking with Chrome's Developer Tools, the only problem I can see is this:

var nivo-child = $(this);

You can't have a dash in a variable name, change it to nivo_child or nivoChild.


To fix the second error, you need to use jQuery.noConflict().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文