Changing data content on an Object Tag in HTML

前端 未结 14 2056
抹茶落季
抹茶落季 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:08

    This snippet did the job in my case

      var object = document.getElementById(objectID);
      object.setAttribute('data', newData);
    
      var clone = object.cloneNode(true);
      var parent = object.parentNode;
    
      parent.removeChild(object );
      parent.appendChild(clone );
    
    0 讨论(0)
  • 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 + '"');
    
    0 讨论(0)
提交回复
热议问题