innerHTML doesn't work in IE11 and IE8

别说谁变了你拦得住时间么 提交于 2019-12-01 04:16:30

问题


I use these codes for refreshing a part of my page :

var container = document.getElementById("mainForm:table_1");
var content = container.innerHTML;
container.innerHTML= content;

container.innerHTML worked well in firefox and chrome but it doesn't work in IE8 and IE11

I've read these links : .InnerHTML Not working properly in Internet Explorer and document.getElementById().innerHTML fails with 'Unknown Error' in IE

but my problem is that I can't change the other part of my code easily due to of dynamically generation.

1) Is there any way that I can do just with these part of my code to solve IE problem ?

2) and also i need an alternative for :

window.history.pushState()

which doesn't work in IE8 and IE9


回答1:


for first part of your question do this :

  var container = document.getElementById("mainForm:table_1").parentNode;
  var content = container.innerHTML
  container.innerHTML= content;

and for second part of your question as @JITHIN PV said you must use history.js

you can easily use it like this :

var History = window.History;
History.enabled ;
History.pushState("object or string", "object or string", "object or string");



回答2:


IE9 and below doesn't support pushState. For unsupported browsers use history API. and also find some more list of polyfills here.




回答3:


It seems IE 11 does not refresh an element if the new content set to its innerHTML is the same than its actual content.
My problem was that in <img src='some_url'...> the 'some_url' string was the same even if its content was changed.
To solve this I added milliseconds at the end of some_url so it becomes : <img src='some_url&time=' + new Date().getTime() ...>



来源:https://stackoverflow.com/questions/25969386/innerhtml-doesnt-work-in-ie11-and-ie8

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