开发者

Does IE7 not fully support javascript's insertBefore method?

I have the following code which wor开发者_开发知识库ks 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


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜