相关文章推荐
咆哮的牛肉面  ·  SignalR Hub 在 .NET ...·  1 月前    · 
孤独的钢笔  ·  jQuery ...·  4 周前    · 
还单身的松球  ·  jquery ...·  4 周前    · 
完美的抽屉  ·  jquery ...·  4 周前    · 
英勇无比的苹果  ·  django ...·  7 月前    · 
英俊的大象  ·  Databricks Runtime ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am loading a .js file I wrote. Within that .js file I am creating a Iframe like this

var frmSource = "http://MYLINK.com/mypage.php?" + encodeURI(URLBuilder);
ifrm = document.createElement("IFRAME");
ifrm.setAttribute("src", frmSource);a
ifrm.style.width = 0+"px";
ifrm.style.height = 0+"px";
ifrm.setAttribute("frameBorder", "0");
document.body.appendChild(ifrm);

URLBuilder contains the GET variables to the next page
The issue occurs at document.body.appendChild(ifrm);

and my error is javascript typeerror: null is not an object (evaluating 'document.body.appendchild')

I suspect the issue is it is trying to append the iframe to the body but the body has not properly loaded. I am currently only getting this issue in safari.

I have done something like this to configure my IFrame creation and it is working fine

 var urlWithParam = url + encodeURI(URLBuilder)
        var iframe = document.createElement('iframe');
        iframe.src = urlWithParam;
        iframe.id = "iframe_" + done;
        iframe.style.position = "relative";
        iframe.style.height = "100%";
        iframe.style.width = "100%";
        iframe.style.top = "0";
        iframe.style.left = "0";
        iframe.style.right = "0";
        iframe.style.bottom = "0";
        iframe.style.frameBorder = "0";
        iframe.style.borderStyle = "none";
        iframe.style.display = "none;";
        //if you want to do something after the Iframe load
        iframe.onload = function(event) {
                I am marking this one correct. It is the closest to what I implemented.   I ended up editing the code I provided above to this and seems to work every time           window.onload = function() {         CODE here         };
– Emanuel Permane
                Feb 16, 2015 at 21:28
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.