Does IE7 not fully support javascript's insertBefore method?

拥有回忆 提交于 2019-12-06 02:55:25

问题


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


回答1:


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!




回答2:


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

Details



来源:https://stackoverflow.com/questions/5172202/does-ie7-not-fully-support-javascripts-insertbefore-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!