Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
if (navigator.appName == "Netscape") {
             var PrintCommand = '< OBJECT ID="PrintCommandObject" WIDTH=0 HEIGHT=0 ';
PrintCommand += 'CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
     document.body.insertAdjacentHTML('beforeEnd', PrintCommand);
     PrintCommandObject.ExecWB(6, -1); PrintCommandObject.outerHTML = "";
        }
        else { window.print(); }


It is showing this error:JavaScript runtime error: Unable to get property 'insertAdjacentHTML' of undefined or null reference. I am using IE browser.
how can i get this please help me.
Posted

1 solution

MSDN: insertAdjacentHTML method[^]: Remarks section in the document says:
You cannot insert text while the document is loading. Wait for the onload event to fire before attempting to call this method.

When using the insertAdjacentHTML method to insert script, you must include the DEFER attribute in the script element.


Quite possibly your document has not completely loaded. If you are using jQuery there is a very handy method document.ready()[^] which will be called only after your document has completely loaded. You can put your code inside this method. If you are not sure, make sure your document has completely loaded before this code is called.

Hope that helps!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900