473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

IE only show the first line after set innerHTML.

I have develop a on-line dictionary website, http://www.stardict.org
I meet a problem:
Here is two lines of js codes:
document.getElementById("wordlist").innerHTML = "";
document.getElementById("definition").innerHTML = "line1<br>line2";
The corresponding html codes are:
<table width="100%">
<tr>
<td width="25%" valign="top"><div id="wordlist" width="100%" style='
overflow-y:auto; height:352px;'></div></td>
<td width="8" bgcolor="#888888"></td>
<td width="75%" valign="top"><div id="definition" width="100%" style='
overflow-y:auto; height:352px;'></div></td>
</tr>
</table>
But I will find only the first line1 is showed, you can't see line2. By
alert(document.getElementById("definition").innerH TML) you can find the
content is right. If comment the first line which set wordlist's
innerHTML, the result will be shown correctly.
This problem only happen in IE. It is correct in firefox.
Any one can help me to fix the problem? Thanks!

Oct 3 '06 #1
1 2172

hu********@gmail.com napisal(a):
I have develop a on-line dictionary website, http://www.stardict.org
I meet a problem:
Here is two lines of js codes:
document.getElementById("wordlist").innerHTML = "";
document.getElementById("definition").innerHTML = "line1<br>line2";
The corresponding html codes are:
<table width="100%">
<tr>
<td width="25%" valign="top"><div id="wordlist" width="100%" style='
overflow-y:auto; height:352px;'></div></td>
<td width="8" bgcolor="#888888"></td>
<td width="75%" valign="top"><div id="definition" width="100%" style='
overflow-y:auto; height:352px;'></div></td>
</tr>
</table>
But I will find only the first line1 is showed, you can't see line2. By
alert(document.getElementById("definition").innerH TML) you can find the
content is right. If comment the first line which set wordlist's
innerHTML, the result will be shown correctly.
This problem only happen in IE. It is correct in firefox.
Any one can help me to fix the problem? Thanks!
I have testes followin example on FF/IE 6 and it works, maybe it will
help ;-):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
</head>
<body>
<script type="text/javascript">
// a counter used to create unique IDs
var Utils = new Object();
Utils.addEvent_guid = 1;

/**
* Rejestruje funkcje obslugi wybranego zdarzenia dla wskazanego
elementu DOM.
* TODO: zrobic anonynomous function execution...w której bedzie
wybór metody,
* np. wpierw preferowac DOM'a czyli [elem].addEventListener();
*
* @param element referencja do elementu DOM (tworzona/uzywana
* jest wlasciwosc events tego elementu(typu Object), która
zawiera
* strukture
"nazwa_zdarzenia"->[lista_funkcji_obslugi_zdarzenia(Object)]
*
* @param type nazwa zdarzenia np. click
* @param handler referencja do funkcji obslugi zdarzenia
(przypisywana jest mu
* wlasciwosc $$guid, która jest unikalnym numerem
(wzgledem wszystkich
* funckji obslugi zdarzen))
*/
Utils.addEvent = function(element, type, handler)
{
// assign each event handler a unique ID
// , but what about concurency, (thread races etc. ?), we assume here
// that script is running always in ONE thead...(so it is fine below).
// This is sury true for IE, where event object is a property of
global
// object window (window.event), so for this to work the events must
be
// fired in sequence...
if (!handler.$$guid) handler.$$guid = Utils.addEvent_guid++;
// create a hash table of event types for the element
if (!element.events) element.events = new Object();
// create a hash table of event handlers for each element/event pair
var handlers = element.events[type];
if (!handlers) {
handlers = element.events[type] = new Object();
// store the existing event handler (if there is one)
if (element["on" + type]) {
handlers[0] = element["on" + type];
}
}
// store the event handler in the hash table
handlers[handler.$$guid] = handler;
// assign a global event handler to do all the work
element["on" + type] = Utils.handleEvent;
};

/**
* Usuwa zarejestrowana funkcje obslugi zdarzenia.
*/
Utils.removeEvent = function(element, type, handler)
{
// delete the event handler from the hash table
if (element.events && element.events[type]) {
delete element.events[type][handler.$$guid];
}
};

/**
*
*/
Utils.fixEvent_preventDefault = function()
{
this.returnValue = false;
};

/**
*
*/
Utils.fixEvent_stopPropagation = function()
{
this.cancelBubble = true;
};

/**
* "Poprawia" obiekt event w przegladarkach IE (window.event)
*/
Utils.fixEvent = function(event)
{
// add W3C standard event methods for browsers that do not supports
them(IE)
event.preventDefault = Utils.fixEvent_preventDefault;
event.stopPropagation = Utils.fixEvent_stopPropagation;
return event;
};

/**
* Jest wolana, gdy nalezy obsluzyc zdarzenie danego typu (jej
funkcja to
* wolanie wlasciwej funckji obslugi zdarzenia zarejestrowanej
poprzez
* Utils.addEvent()).
*/
Utils.handleEvent = function(event)
{
var returnValue = true;
// grab the event object (IE uses a global event object)
event = event || Utils.fixEvent(window.event);
// get a reference to the hash table of event handlers
var handlers = this.events[event.type];
// execute each event handler
for (var i in handlers) {
this.$$handleEvent = handlers[i];
if (this.$$handleEvent(event) === false) {
returnValue = false;
}
}
return returnValue;
};

/**
* @return szerokosc elementu wraz z padding i border (IE)
*/
Utils.getElementWithId = function() {
var getElementWithId = function() {};

if(document.getElementById) {
getElementWithId = function(id) {
return document.getElementById(id);
};
} else if(document.all) {
getElementWithId = function(id) {
return document.all[id];
};
} else if(document.layers) {
getElementWithId = function(id) {
return document[id];
}
}
return getElementWithId;
}();
Utils.addEvent(window, 'load', function() {
alert('ok');
Utils.getElementWithId("wordlist").innerHTML = "";
Utils.getElementWithId("definition").innerHTML = "line1<br>line2";
});

</script>

<table>
<tr>
<td><div id="wordlist" width="100%"></div></td>
<td bgcolor="#888888"></td>
<td valign="top"><div id="definition"></div></td>
</tr
</table
</body>
</html>

Greets
Luke Matuszewski

Oct 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Roger Godefroy | last post by:
Hi There, I would like to show details in another (hidden) TR. It should look like something like on an image I have found wich illustrates it exactly is I want: ...
13
by: kaeli | last post by:
Can anyone explain this to me? It's driving me insane. Save this and run it in IE or Opera and then in Mozilla or Netscape 6+. In IE/Opera, I get the expected 4 alerts. In Mozilla/Netscape, I...
2
by: John Doe | last post by:
I have a webpage which shows and hides divs as a method of navigation. It works great in the ever evil IE. It works not so great (read not at all) in any standards compliant browser. I haven't...
1
by: Mel | last post by:
i use the following to add a line. how can i delete the last line ? oDiv = document.getElementById("MyDiv"); oDiv.innerHTML = oDiv.innerHTML + string;
2
by: Eero Tuomenoksa | last post by:
Hi Does someone knows how i can show/hide multible divs at one click? -- Käytössä Operan vallankumouksellinen sähköpostiohjelma: http://www.opera.com/mail/
3
by: Just D. | last post by:
All, What's the simplest way to show my own HTML string on the ASPX page assuming that this page is just created using the wizard and it has nothing on it? We're free to use any control adding...
1
by: preet | last post by:
On first execution of StartSurf() the siteloc returns undefined On second excution and after that there is no problem. StartSurf is called from a button press, which becomes invisible for 30...
12
by: Rahaman sharif | last post by:
Hi All, I have some problem in innerHtml. I have the textbox in innerHtml, In the innerHtml textbox was read only. I want make it to enable. if user enter the text that text will be retrieved, so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.