Internet explorer IE 8:对象不';t支持属性或方法';getElementsByClassName';

Internet explorer IE 8:对象不';t支持属性或方法';getElementsByClassName';,internet-explorer,error-handling,prototypejs,slider,Internet Explorer,Error Handling,Prototypejs,Slider,我使用的是diapo滑块,除了InternetExplorer8之外,它似乎在所有其他浏览器中都能工作 在调试模式下运行ie8后,我出现以下错误: SCRIPT438:对象不支持属性或方法 “getElementsByClassName”prototype.js,第5988行字符5 SCRIPT438:对象不支持属性或方法“fireEvent” prototype.js,第5736行字符7 我在magento平台上运行这个滑块,看起来原型脚本出现了问题。它使用的原型版本是1.7,因此排除了可能的

我使用的是diapo滑块,除了InternetExplorer8之外,它似乎在所有其他浏览器中都能工作

在调试模式下运行ie8后,我出现以下错误:

SCRIPT438:对象不支持属性或方法 “getElementsByClassName”prototype.js,第5988行字符5

SCRIPT438:对象不支持属性或方法“fireEvent” prototype.js,第5736行字符7

我在magento平台上运行这个滑块,看起来原型脚本出现了问题。它使用的原型版本是1.7,因此排除了可能的脚本更新修复

注意:虽然我在ie9中没有显示问题,但我得到以下错误:

SCRIPT438:对象不支持属性或方法“dispatchEvent” prototype.js,第5734行,字符7

这些是DIPO滑块工作所需的脚本,在标题中加载脚本标记。我不确定,但可能其中一些脚本与现有脚本冲突:

<script type='text/javascript' src='http://www.pixedelic.com/plugins/diapo/scripts/jquery.min.js'></script>
<script type='text/javascript' src='http://www.pixedelic.com/plugins/diapo/jquery.mobile-1.0rc2.customized.min.js'></script>
<script type='text/javascript' src='http://www.pixedelic.com/plugins/diapo/jquery.easing.1.3.js'></script>
<script type='text/javascript' src='http://www.pixedelic.com/plugins/diapo/jquery.hoverIntent.minified.js'></script>
<script type='text/javascript' src='http://www.pixedelic.com/plugins/diapo/scripts/diapo.js'></script>

IE8确实支持。但是,它支持。因此,我建议使用
querySelectorAll
编写一个polyfill

document.getElementsByClassName('foo')
变成

document.querySelectorAll('.foo'); // Prefixed dot.
请注意Prototype.js和

IE8的快速修复:

<!--[if IE 8]><script>
document.getElementsByClassName = 
Element.prototype.getElementsByClassName = function(class_names) {
    // Turn input in a string, prefix space for later space-dot substitution
    class_names = (' ' + class_names)
        // Escape special characters
        .replace(/[~!@$%^&*()_+\-=,./';:"?><[\]{}|`#]/g, '\\$&')
        // Normalize whitespace, right-trim
        .replace(/\s*(\s|$)/g, '$1')
        // Replace spaces with dots for querySelectorAll
        .replace(/\s/g, '.');
    return this.querySelectorAll(class_names);
};
</script><![endif]-->

注:

  • 它确实支持多个类名
  • 它不支持空(
    '
    )类名。如果您愿意,添加对这些的支持是很简单的

演示:

谢谢Rob,但我如何应用此修复程序?…我更新了我的帖子,提供了有关所用脚本的更多相关细节。请让我知道这是否有帮助。非常感谢!您正在同一页面上使用jQuery和Prototype.js。他们有没有可能互相冲突?Diapo不使用Prototype.js,但你仍然会收到Prototype.js相关的错误。是的,Prototype脚本是magento平台的一部分,因此默认情况下会上载它…我可以尝试在主页上禁用它,但我对你的polyfill解决方案感兴趣too@gdinari请参阅polyfill的更新答案。这必须在Prototype.jsPerfect之前包含!谢谢你,罗布。为了这次修复,几天来折磨我的大脑是值得的。再次感谢
document.getElementsByClassName('foo')
document.querySelectorAll('.foo'); // Prefixed dot.
<!--[if IE 8]><script>
document.getElementsByClassName = 
Element.prototype.getElementsByClassName = function(class_names) {
    // Turn input in a string, prefix space for later space-dot substitution
    class_names = (' ' + class_names)
        // Escape special characters
        .replace(/[~!@$%^&*()_+\-=,./';:"?><[\]{}|`#]/g, '\\$&')
        // Normalize whitespace, right-trim
        .replace(/\s*(\s|$)/g, '$1')
        // Replace spaces with dots for querySelectorAll
        .replace(/\s/g, '.');
    return this.querySelectorAll(class_names);
};
</script><![endif]-->