Changing data content on an Object Tag in HTML

前端 未结 14 2133
抹茶落季
抹茶落季 2020-11-29 08:06

I have an HTML page which contains an Object tag to host an embedded HTML page.



        
      
      
      
14条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 09:09

    This seems to be a browser bug, setAttribute() should work. I found this workaround, which seems to work in all browsers:

    var newUrl = 'http://example.com';
    var objectEl = document.getElementById('contentarea');
    objectEl.outerHTML = objectEl.outerHTML.replace(/data="(.+?)"/, 'data="' + newUrl + '"');
    

提交回复
热议问题