开发者

Accessing iFrame Contents via jQuery in IE

开发者 https://www.devze.com 2022-12-17 05:51 出处:网络
I\'m using jQuery to try and access the contents of an iframe WYSIWYG, just to get the character count and update a counter outside the iFrame. Oddly enough, my code works fine in in Firefox, but brea

I'm using jQuery to try and access the contents of an iframe WYSIWYG, just to get the character count and update a counter outside the iFrame. Oddly enough, my code works fine in in Firefox, but breaks in all versions of IE. Wondering if anyone could help me out with some IE-friendly syntax? Here's what I have so far:

This is in the onload function:

textCounterWYSIWYG('longDesc_cnt', 2000);

This is the function itself:

function textCounterWYSIWYG(text, limit) {
  var len = String($("iframe").contents().find("body").html());
  var trimmed = len.replace(/^\s+|\s+$/g, '');
  var length = trimmed.length;
  if (length > limit) {
    field.value = field.value.substring(0, maxlimit);
  }
  else {
    var rem = limit - len开发者_StackOverflow社区gth;
    $("#"+text).text(rem + " Characters Remaining");
  }
}

The var len = ... line is what seems to be breaking IE. Any thoughts/suggestions are highly welcome!


First thing I would try is to get the iframe by id rather than by tag name.

Also, I'd change that variable name "len" to something more relevant ;-).


Perhaps it is some default IE security settings? What WYSIWYG library are you using?

0

精彩评论

暂无评论...
验证码 换一张
取 消