Solved

document.write causes the ie page to go blank?

Posted on 2012-04-12
14
869 Views
Last Modified: 2012-04-27
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>");

........
}
0
Comment
Question by:JohnPaddock
  • 7
  • 4
  • 3
14 Comments
 
LVL 19

Assisted Solution

by:Bardobrave
Bardobrave earned 334 total points
ID: 37838234
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
 

Author Comment

by:JohnPaddock
ID: 37838364
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
 
LVL 19

Accepted Solution

by:
Bardobrave earned 334 total points
ID: 37838429
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
 
LVL 38

Assisted Solution

by:Tom Beck
Tom Beck earned 166 total points
ID: 37838460
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
 
LVL 19

Expert Comment

by:Bardobrave
ID: 37838546
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
 

Author Comment

by:JohnPaddock
ID: 37838955
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
 

Author Comment

by:JohnPaddock
ID: 37838960
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 38

Expert Comment

by:Tom Beck
ID: 37839031
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
 

Author Comment

by:JohnPaddock
ID: 37839177
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
 

Author Comment

by:JohnPaddock
ID: 37839192
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
 
LVL 38

Expert Comment

by:Tom Beck
ID: 37839332
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
 
LVL 19

Expert Comment

by:Bardobrave
ID: 37841246
The correct text for the tagname function is:

document.getElementsByTagName("body")
0
 

Author Comment

by:JohnPaddock
ID: 37903518
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
 

Author Closing Comment

by:JohnPaddock
ID: 37903544
It sounds like what the consultant did was pretty much what Bardobrave suggested in his first comment.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now