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>");

........
}
JohnPaddockAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BardobraveCommented:
You are posting "<object id='theobj' classid='clsid:0389FBBA-6E36-4F5D-9B9D-C702E3807B7F'></object>" to your current page.

This is quite awful, but, of course, it could depend on what you are trying to.

If, as I supose, you want to load a Java component on your page, what you should do is to reserve a space onto your page for the component and load the component into this space.

for example:

On your html code:

<div id="javaContainer">
<!-- Java component will be loaded here" -->
</div>

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

........
}


This is prettier.
0
JohnPaddockAuthor Commented:
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
0
BardobraveCommented:
Let's see...

What document.write does is to write the string you pass to it into the page's DOM. The worst part of it is that document.write wypes out all the rest of the content on the page and replaces it by the content you are passing it. So what you are doing is loading a blank page with an <object> tag.

My J2EE is quite rusty, but your js file must be called from some place, usually it's stored, loaded and executed from within a page, that page will be wyped when you use document.write.

Although the page codes is created dinamically, I supose that you can edit the code that dinamically creates them and add a container for your <object> tag, if you can't you always can do document.getElementByTagName("body").innerHTML += "<object id='theobj' classid='clsid:0389FBBA-6E36-4F5D-9B9D-C702E3807B7F'></object>"; (suposing that your page has a <body> tag).

However, the problem with IE points to some type of problem with the java component and the java addon from IE. Try to open a page with the object in IE and see if it opens ok at the first try or you need to reload it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tom BeckCommented:
How about this:

var newDiv = document.createElement('div');
newDiv.appendChild('<object id='theobj' classid='clsid:0389FBBA-6E36-4F5D-9B9D-C702E3807B7F'></object>');
document.body.appendChild(newDiv');
0
BardobraveCommented:
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?
0
JohnPaddockAuthor Commented:
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
0
JohnPaddockAuthor Commented:
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>
0
Tom BeckCommented:
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");
}
0
JohnPaddockAuthor Commented:
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
0
JohnPaddockAuthor Commented:
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");
}
0
Tom BeckCommented:
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.
0
BardobraveCommented:
The correct text for the tagname function is:

document.getElementsByTagName("body")
0
JohnPaddockAuthor Commented:
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
0
JohnPaddockAuthor Commented:
It sounds like what the consultant did was pretty much what Bardobrave suggested in his first comment.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.