Changing data content on an Object Tag in HTML

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

    You can do it with setAttribute

    document.getElementById("contentarea").setAttribute('data', 'newPage.html');
    

    EDIT: It is also recommended that you use the window.onload to ensure that the DOM has loaded, otherwise you will not be able to access objects within it.

    It could be something like this:

    function changeData(newURL) {
        if(!document.getElementById("contentarea")) 
            return false;
        document.getElementById("contentarea").setAttribute('data', newURL);
    }
    
    window.onload = changeData;
    

    You can read more about window.onload here

提交回复
热议问题