javascript - 即8 'Invalid Pointer'

标签 javascript jquery internet-explorer internet-explorer-8 coffeescript

我有一个用 CoffeeScript 编写的函数,以前工作正常,但现在在 ie8 中抛出“无效指针”异常。

CoffeeScript

convertSVGforIE = ->

  if not $.support.svg or device.ff36
    imagesToConvert = $('img.SVG')
    imagesToConvert.each ->
      imageSrcMinus = this.src.substr 0, this.src.length - 3
      this.src = imageSrcMinus + 'png'

Javascript

convertSVGforIE = function() {
    var imagesToConvert;
    if (!$.support.svg || device.ff36) {
      imagesToConvert = $('img.SVG');
      return imagesToConvert.each(function() {
        var imageSrcMinus;
        imageSrcMinus = this.src.substr(0, this.src.length - 3); //Invalid pointer
        return this.src = imageSrcMinus + 'png';
      });
    }
};

我看不出我的脚本有什么问题。请帮我确定一下,ie8的问题是什么。

更新: 我让它工作了,但不是很好

convertSVGforIE = ->

  if not $.support.svg or device.ff36
    $('img.SVG').each ->
      that = $(this)
      imageSrcMinus = that.attr('src').substr 0, that.attr('src').length - 3
      that.attr 'src', imageSrcMinus+'png'

上面的脚本可以工作,但是为什么 $(this).attr('src') 可以工作呢?而 this.src 没有?为什么只在 IE 中?

最佳答案

实际上,所有版本的 IE 都支持图像的 .src 属性。 MSDN 文档相当令人困惑,因为它似乎暗示该属性仅在 IE8 或更高版本中受支持;但这是错误的。

然而,当您尝试读取数据 URI 大于 4K 的图像的 .src 时,IE8 中会出现无效指针错误。此错误记录在 http://support.microsoft.com/kb/2688188建议的修复方法是更新您的浏览器。

但是有一个简单的解决方法,那就是引用图像属性集合中的SRC,即代替这个:

img.src

使用这个:

img.attributes.src.value

关于javascript - 即8 'Invalid Pointer',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9659251/

相关文章:

javascript - React Component 有条件地渲染子项不能按我希望的那样工作

javascript - 如何在 Angular js 中的 .run 方法内调用读取 json 文件的工厂?是否可能?

jquery - 全日历在移动中改变颜色

javascript - 如何通过 javascript/jQuery 从 CSS 类获取样式属性?

javascript - 移动设备上的图像拖动故障

asp.net - ASPX +渐变SVG在Visual Studio 2010上不起作用

javascript - 如何处理 IE select onchange 和 ajax 请求

javascript - Uncaught TypeError:无法在playAudio读取null的属性 'play'

javascript - 在 html 文本框或输入框中键入卡纳达语

javascript - 如果浏览器 lt ie9 执行某些 javascript