Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

document.write causes the ie page to go blank?

Posted on 2012-04-12
14
Medium Priority
?
897 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 3
14 Comments
 
LVL 19

Assisted Solution

by:Bardobrave
Bardobrave earned 1336 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 1336 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 38

Assisted Solution

by:Tom Beck
Tom Beck earned 664 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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

722 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