Link to home
Start Free TrialLog in
Avatar of JohnPaddock
JohnPaddock

asked on

document.write causes the ie page to go blank?

I have a javascript function that a jsp file calls with an onclick event.
Everthing works great, however when clicking the link in ie, the page goes blank (the fuction works though).  hitting F5 brings it back, but how can I avoid the page going blank?  It seems to be the document.write line below that causes this.  Is there a better way to do whatever that line is doing? maybe a different command other than document.write?

function IA_dialer2(number)
{
  document.write("<object id='theobj' classid='clsid:0389FBBA-6E36-4F5D-9B9D-C702E3807B7F'></object>");

........
}
SOLUTION
Avatar of Bardobrave
Bardobrave
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JohnPaddock
JohnPaddock

ASKER

The html pages for this are all created dynamically, so I can't really change anything in the html code directly.  Basically, I got this function from cisco's click-to-call widget, it comes from an html file that the cisco software installs.   When we added the fuction on our interaction webserver js file, we had to put document.write in front of the line, not really sure why.

the below line came from a cisco htm file
<object id="theobj" classid="clsid:0389FBBA-6E36-4F5D-9B9D-C702E3807B7F"></object>

when we added it to our js file, we had to change it to
  document.write("<object id='theobj' classid='clsid:0389FBBA-6E36-4F5D-9B9D-C702E3807B7F'></object>";

so I don't think I can try what you're saying since I can't control the html pages for this, but there must be a better way of 'running' the line without the document.write.  maybe document.run?  .run doesn't work though
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Seems pretty (although I'm not sure about document.body to be an object right now).

Have you tried to load a simple page with the <object> tag on IE to see if the problem is related to the java component and the IE java addon?
When I use the below line, I get the error that is below.
document.getElementByTagName("body").innerHTML += "<object id='theobj' classid='clsid:0389FBBA-6E36-4F5D-9B9D-C702E3807B7F'></object>";

Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MS-RTC LM 8; .NET4.0C; .NET4.0E)
Timestamp: Thu, 12 Apr 2012 17:24:19 UTC
Message: Object doesn't support this property or method
Line: 9225
Char: 1
Code: 0
URI: http://interactionapp/IA_SCRIPTS/InterAction.js



when I use tommyboys code, the page doesn't load and gives the below errors

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MS-RTC LM 8; .NET4.0C; .NET4.0E)
Timestamp: Thu, 12 Apr 2012 17:32:34 UTC


Message: Expected ')'
Line: 9224
Char: 33
Code: 0
URI: http://interactionapp/IA_SCRIPTS/InterAction.js


Message: Object expected
Line: 160
Char: 2
Code: 0
URI: http://interactionapp/InterAction/myContacts?proxyAccount=


Message: 'IA_resize' is undefined
Line: 180
Char: 2
Code: 0
URI: http://interactionapp/InterAction/myContacts?proxyAccount=


Message: Object expected
Line: 1
Char: 1
Code: 0
URI: http://interactionapp/InterAction/myContacts?proxyAccount=


Message: Object expected
Line: 1
Char: 1
Code: 0
URI: http://interactionapp/InterAction/myContacts?proxyAccount=


Message: Object expected
Line: 1
Char: 1
Code: 0
URI: http://interactionapp/InterAction/myContacts?proxyAccount=


Message: Object expected
Line: 1
Char: 1
Code: 0
URI: http://interactionapp/InterAction/myContacts?proxyAccount=


Message: 'IA_resizeIdx' is undefined
Line: 5698
Char: 5
Code: 0
URI: http://interactionapp/IA_SCRIPTS/grid2.js


Message: Object expected
Line: 1
Char: 1
Code: 0
URI: http://interactionapp/InterAction/myContacts?proxyAccount=


Message: 'IA_resizeIdx' is undefined
Line: 5698
Char: 5
Code: 0
URI: http://interactionapp/IA_SCRIPTS/grid2.js


Message: Object expected
Line: 1
Char: 1
Code: 0
URI: http://interactionapp/InterAction/myContacts?proxyAccount=


Message: 'IA_resizeIdx' is undefined
Line: 5698
Char: 5
Code: 0
URI: http://interactionapp/IA_SCRIPTS/grid2.js


Message: Object expected
Line: 1
Char: 1
Code: 0
URI: http://interactionapp/InterAction/myContacts?proxyAccount=


Message: 'IA_resizeIdx' is undefined
Line: 5698
Char: 5
Code: 0
URI: http://interactionapp/IA_SCRIPTS/grid2.js


Message: 'IA_resizeIdx' is undefined
Line: 5698
Char: 5
Code: 0
URI: http://interactionapp/IA_SCRIPTS/grid2.js


Message: Object expected
Line: 1
Char: 1
Code: 0
URI: http://interactionapp/InterAction/myContacts?proxyAccount=


Message: 'IA_resizeIdx' is undefined
Line: 5698
Char: 5
Code: 0
URI: http://interactionapp/IA_SCRIPTS/grid2.js


Message: 'IA_resizeIdx' is undefined
Line: 5698
Char: 5
Code: 0
URI: http://interactionapp/IA_SCRIPTS/grid2.js


Message: Object expected
Line: 1
Char: 1
Code: 0
URI: http://interactionapp/InterAction/myContacts?proxyAccount=


Message: 'IA_resizeIdx' is undefined
Line: 5698
Char: 5
Code: 0
URI: http://interactionapp/IA_SCRIPTS/grid2.js


Message: 'IA_resizeIdx' is undefined
Line: 5698
Char: 5
Code: 0
URI: http://interactionapp/IA_SCRIPTS/grid2.js


Message: Object expected
Line: 136
Char: 3
Code: 0
URI: http://interactionapp/IA_SCRIPTS/ia_init.js
I'm not sure if this answers your question, but when I put the below text in an html file and open the page, it works (after an activex warning)

<object id="theobj" classid="clsid:0389FBBA-6E36-4F5D-9B9D-C702E3807B7F"></object>

<script>


  var sNewText      = "8465";


  if(sNewText.length <= 32)
    {
        if(sNewText == "")
        {
            
      }
        theobj.StartVoiceCall(sNewText);
   }
   else
   {
         alert("dd");

 }

</script>
Fix the first error and the others may go away. You have a parenthesis missing somewhere.

Message: Expected ')'
Line: 9224
Char: 33
Code: 0

You could also as a test try something like this just to see if you are attempting to run the code before the body even exist in the DOM:
if(document.body != null){
   var newDiv = document.createElement('div');
   newDiv.appendChild('<object id='theobj' classid='clsid:0389FBBA-6E36-4F5D-9B9D-C702E3807B7F'></object>');
   document.body.appendChild(newDiv');
}else{
   alert("body null");
}
I revised tommyboys code by adding a ' before the newdiv, and changing some single quotes to double quotes.

var newDiv = document.createElement('div');
newDiv.appendChild("<object id='theobj' classid='clsid:0389FBBA-6E36-4F5D-9B9D-C702E3807B7F'></object>");
document.body.appendChild('newDiv');

not it gives this error
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MS-RTC LM 8; .NET4.0C; .NET4.0E)
Timestamp: Thu, 12 Apr 2012 18:02:42 UTC

Message: Type mismatch.

Line: 9224
Char: 1
Code: 0
URI: http://interactionapp/IA_SCRIPTS/InterAction.js
I tried using the code you mentioned below, but it's giving the same type mismatch error


if(document.body != null){
   var newDiv = document.createElement('div');
   newDiv.appendChild("<object id='theobj' classid='clsid:0389FBBA-6E36-4F5D-9B9D-C702E3807B7F'></object>");
   document.body.appendChild('newDiv');
}else{
   alert("body null");
}
The TypeMismatch coming for IE only, correct?

Are you sure the TypeMismatch error is because of the code I suggested? Does it NOT happen when the code is commented out? TypeMismatch errors generally result in IE when adding event listeners using javascript.
The correct text for the tagname function is:

document.getElementsByTagName("body")
nothing I was doing was working (I'm not a java programming at all so I was getting frustrated), so we got a consultant to fix it.  I don't really know exactley what he did, but I think he moved that object id='theobj'.... line from the function in the js file, to 2 other jsp files so the object already gets loaded when the page loads so the onclick event doesn't need to load it(causing a blank line).  If I was more familier with js and jsp though I'm sure I could have worked through it with your suggestions/help.  

thanks
It sounds like what the consultant did was pretty much what Bardobrave suggested in his first comment.