<object> works in every browser except Google Chrome

廉价感情. 提交于 2021-02-10 15:51:34

问题


I have a problem with loading data into an < object > using Javascript. It refuses to work in Chrome, no error message either.

You can see a minimal example to play with here: http://tinkerbin.com/HIqG0ypb


回答1:


It is strange to me that browsers assume object.data could be set as URI but display content available at that URI. It sounds like a security flaw : full content could be injected into a page without using frame. I wonder if test.com in your example has access to window.parent or something like that

[EDIT]

So

<script type="text/javascript">
  function openFrame() {
    document.getElementById('testFrame').data="http://test.com";
  }
</script>

Must be written for Chrome as :

<script type="text/javascript">
  function openFrame() {
    document.getElementById('testFrame').data="http://test.com";
    var el = document.getElementById("testFrame");
    var h = el.innerHTML;
    el.innerHTML = h;
  }
</script>

where testFrame is :

  <object id="testFrame" type="text/html" style="overflow-x: hidden; width: 100%; height: 100%" />


来源:https://stackoverflow.com/questions/11245385/object-works-in-every-browser-except-google-chrome

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