Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

document.body.appendChild(i)

I am getting error only in IE7 as document.body is null; when I debug with Microsoft script editor I am getting the error in the following line: i.e.

document.body.appendChild(i)

Code:

function nm_eraseCookie(name){     nm_createCookie(name,"",-1) } var i=document.createElement('IMG'); i.src='//e.netmng.com/pixel/?aid=403'; i.width=1; i.height=1; document.body.appendChild(i); nm_createCookie('nm_belgacom_bt', escape('tv1=bun_intvtel;tv2=;tv3=;phone1=hbs_discoveryline;phone2=hbs_classical_line;phone3=;inet1=bun_nettvmob;inet2=hbs_adsl_res_plus;inet3=hbs_adsl_res_go;nm_banner=;nm_popin=hbs_discoveryline;'),183); 

Can you inform me what I need to do to solve this issue?

like image 329
san Avatar asked Mar 24 '11 13:03

san


People also ask

What is the use of document body appendChild?

appendChild() The appendChild() method of the Node interface adds a node to the end of the list of children of a specified parent node. If the given child is a reference to an existing node in the document, appendChild() moves it from its current position to the new position.

What is append and appendChild?

append() allows you to also append string objects, whereas Node. appendChild() only accepts Node objects. Element. append() has no return value, whereas Node. appendChild() returns the appended Node object.

What is the difference between append ()` and appendChild?

append() Accepts Node Objects/DOMStrings But appendChild() Only Accepts Node Objects. Node Objects → which are element nodes, text nodes etc.

What is append to body?

append() is a method that adds (an) additional element(s) to the end of the selected parent element. $('body').append('<div>Appended to BODY</div>'); Before: <body> </body> After: <body> <div>Appended to BODY</div> </body>


1 Answers

You could try

document.getElementsByTagName('body')[0].appendChild(i); 

Now that won't do you any good if the code is running in the <head>, and running before the <body> has even been seen by the browser. If you don't want to mess with "onload" handlers, try moving your <script> block to the very end of the document instead of the <head>.

like image 165
Pointy Avatar answered Oct 22 '22 14:10

Pointy