DOCUMENT.BODY.APPENDCHILD HAS A NULL VALUE.

Goti Bandu

Total Post:119

Points:835
Posted by  Goti Bandu
 1131  View(s)
Ratings:
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.

  1. Ashish Pandey

    Post:128

    Points:898
    Re: document.body.appendchild has a null value.

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!