internet explorer - Trying to inject javascript into my page - Stack Overflow

For reasons too plicated to get into now, I have an ajax call that returns some dynamically created Jav

For reasons too plicated to get into now, I have an ajax call that returns some dynamically created Javascript that I want to inject into my page. The following code works on Chrome, but not in IE:

 var node = document.getElementsByTagName("head")[0] || document.body;
  if (node)
  {
    var script = document.createElement("script");
    script.type = "text/javascript";
    //script.innerHTML = json.javascript;
    var textnode = document.createTextNode(json.javascript);
    script.appendChild(textnode);
    node.appendChild(script);
  }

In IE, I get "SCRIPT65535: Unexpected call to method or property access." As you can see from the mented out code, before I tried the textnode, I tried just inserting it with script.innerHTML. That also worked in Chrome, but in IE I got "SCRIPT600:Unknown runtime error".

Is there a way to stick some javascript into the DOM in IE?

For reasons too plicated to get into now, I have an ajax call that returns some dynamically created Javascript that I want to inject into my page. The following code works on Chrome, but not in IE:

 var node = document.getElementsByTagName("head")[0] || document.body;
  if (node)
  {
    var script = document.createElement("script");
    script.type = "text/javascript";
    //script.innerHTML = json.javascript;
    var textnode = document.createTextNode(json.javascript);
    script.appendChild(textnode);
    node.appendChild(script);
  }

In IE, I get "SCRIPT65535: Unexpected call to method or property access." As you can see from the mented out code, before I tried the textnode, I tried just inserting it with script.innerHTML. That also worked in Chrome, but in IE I got "SCRIPT600:Unknown runtime error".

Is there a way to stick some javascript into the DOM in IE?

Share Improve this question asked Jan 2, 2013 at 1:34 Paul TomblinPaul Tomblin 183k59 gold badges323 silver badges411 bronze badges 5
  • You are probably better off using jquery since you won't have to worry about certain features implemented differently in IE. – scartag Commented Jan 2, 2013 at 1:38
  • If you know of a way to do this with jQuery, please let me know. $(node).html isn't working any better than script.innerHTML. – Paul Tomblin Commented Jan 2, 2013 at 1:39
  • Maybe this helps: stackoverflow./questions/8610574/… – regulatethis Commented Jan 2, 2013 at 1:40
  • @regulatethis, both the solutions on that question use innerHTML, which doesn't work in IE. – Paul Tomblin Commented Jan 2, 2013 at 1:42
  • 1 Looks like there are some security restrictions with IE, here is a discussion about it. stackoverflow./questions/703705/… – specialscope Commented Jan 2, 2013 at 1:42
Add a ment  | 

1 Answer 1

Reset to default 6

And of course, as soon as I post this, I find http://www.phpied./dynamic-script-and-style-elements-in-ie/

  var node = document.getElementsByTagName("head")[0] || document.body;
  if (node)
  {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.text = json.javascript;
    node.appendChild(script);
  }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745196137a4616095.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信