Home > DeveloperSection > Forums > document.body.appendchild has a null value.
Goti Bandu

Total Post:119

Points:835
Posted on    March-23-2015 7:23 AM

 JavaScript JQuery  Knockout.js 
Ratings:


 1 Reply(s)
 711  View(s)
Rate this:

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.html?" + 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.



Ashish Pandey

Total Post:128

Points:898
Posted on    March-23-2015 7:59 AM

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) {

 

    };


Modified On Apr-20-2016 01:47:30 AM

Don't want to miss updates? Please click the below button!

Follow MindStick