---
title: "document.body.appendchild has a null value."  
description: "document.body.appendchild has a null value."  
author: "Anonymous User"  
published: 2015-03-23  
updated: 2015-03-23  
canonical: https://www.mindstick.com/forum/23045/document-body-appendchild-has-a-null-value  
category: "javascript"  
tags: ["jquery", "knockout.js"]  
reading_time: 1 minute  

---

# document.body.appendchild has a null value.

I am loading a .js [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) I wrote. Within that .js file I am creating a [Iframe](https://www.mindstick.com/forum/1712/how-to-fit-ifrme-in-mobile-browser) 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](https://www.mindstick.com/articles/715/php-variables) to the next [page](https://www.mindstick.com/articles/13031/why-to-make-a-wikipedia-page)

The issue occurs at document.[body](https://yourviews.mindstick.com/story/2120/rare-species-having-electricity-in-their-body).appendChild(ifrm);

and my [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) is [javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript) [typeerror](https://www.mindstick.com/forum/157755/calling-a-class-member-function-gives-typeerror-in-python-why): [null](https://www.mindstick.com/forum/33922/how-to-use-null-coalescing-operator-in-c-sharp) is not an object (evaluating 'document.body.appendchild')

I suspect the issue is it is [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to append the iframe to the body but the body has not properly loaded. I am currently only getting this issue in safari.

## Replies

### Reply by Anonymous User

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) {     };
```


---

Original Source: https://www.mindstick.com/forum/23045/document-body-appendchild-has-a-null-value

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
