最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

internet explorer 7 - Does IE7 not fully support javascript's insertBefore method? - Stack Overflow

programmeradmin1浏览0评论

I have the following code which works perfect in Chrome, IE8, and FF. However, I get an error when I'm testing it with IE7. Does anyone have a clue what's happening here?

 function do_replace(s, p1,p2,p3,child_node,syn_text) {
       reg = new RegExp('[h\|H][1-7]');
   if(p1.length>0){   //this might not be necessary
     //create textnode
      var text_node = document.createTextNode(p1);
          child_node.parentNode.insertBefore(text_node,child_node);  //errors out here in IE7
       }

The code errors out at the last line- IE7 give an "htmlfile: Invalid argument." error when I look at the code through a debugger. child_node, parentNode, and text_node appear to be formed identical to Firefox and Chrome when running this script.

Any ideas? Or does IE7 just not support this method as well as other browsers?

Thanks

I have the following code which works perfect in Chrome, IE8, and FF. However, I get an error when I'm testing it with IE7. Does anyone have a clue what's happening here?

 function do_replace(s, p1,p2,p3,child_node,syn_text) {
       reg = new RegExp('[h\|H][1-7]');
   if(p1.length>0){   //this might not be necessary
     //create textnode
      var text_node = document.createTextNode(p1);
          child_node.parentNode.insertBefore(text_node,child_node);  //errors out here in IE7
       }

The code errors out at the last line- IE7 give an "htmlfile: Invalid argument." error when I look at the code through a debugger. child_node, parentNode, and text_node appear to be formed identical to Firefox and Chrome when running this script.

Any ideas? Or does IE7 just not support this method as well as other browsers?

Thanks

Share Improve this question asked Mar 2, 2011 at 19:14 user210099user210099 1,1993 gold badges14 silver badges24 bronze badges 1
  • According the MS, IE6+ should support insertBefore. msdn.microsoft./en-us/library/ms536454(v=vs.85).aspx Did you see their remark: "Do not specify the oChildNode parameter when inserting the first child node. If children already exist and you do not specify the oChildNode parameter, the oNewNode bees the last child of the parent object." – Detect Commented Mar 2, 2011 at 19:21
Add a ment  | 

2 Answers 2

Reset to default 4

Rather than leave this problem unsolved, I figured out what was wrong with my code:

I was using an extensive frameset(yuck!!) and when I made the text_node = document.createTextNode() call, I was not doing this in the frame that my application was in.

I fixed this by explicitly calling out the frame to create the object in:

var text_node = MainFrame.child_frame.WhySoManyFrames.document.createTextNode(p1);

After doing this, the insertBefore method works perfect!

Hopefully this helps anyone looking at this question- I know this took me a long time and lots of frustration to figure out!

JavaScript 'InsertBefore' function is supported by IE7. Remember that you have to use this function only when page is fully loaded!

Details

发布评论

评论列表(0)

  1. 暂无评论