hu********@gmai l.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.getEle mentById("wordl ist").innerHTM L = "";
document.getEle mentById("defin ition").innerHT ML = "line1<br>line2 ";
The corresponding html codes are:
<table width="100%">
<tr>
<td width="25%" valign="top"><d iv id="wordlist" width="100%" style='
overflow-y:auto; height:352px;'> </div></td>
<td width="8" bgcolor="#88888 8"></td>
<td width="75%" valign="top"><d iv 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").i nnerHTML) 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].addEventListen er();
*
* @param element referencja do elementu DOM (tworzona/uzywana
* jest wlasciwosc events tego elementu(typu Object), która
zawiera
* strukture
"nazwa_zdarzeni a"->[lista_funkcji_o bslugi_zdarzeni a(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(elemen t, 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.$$gui d) handler.$$guid = Utils.addEvent_ guid++;
// create a hash table of event types for the element
if (!element.event s) 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.handleEve nt;
};
/**
* Usuwa zarejestrowana funkcje obslugi zdarzenia.
*/
Utils.removeEve nt = function(elemen t, 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.returnValu e = false;
};
/**
*
*/
Utils.fixEvent_ stopPropagation = function()
{
this.cancelBubb le = 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.preventDe fault = Utils.fixEvent_ preventDefault;
event.stopPropa gation = 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.handleEve nt = 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.$$handleEv ent = handlers[i];
if (this.$$handleE vent(event) === false) {
returnValue = false;
}
}
return returnValue;
};
/**
* @return szerokosc elementu wraz z padding i border (IE)
*/
Utils.getElemen tWithId = function() {
var getElementWithI d = function() {};
if(document.get ElementById) {
getElementWithI d = function(id) {
return document.getEle mentById(id);
};
} else if(document.all ) {
getElementWithI d = function(id) {
return document.all[id];
};
} else if(document.lay ers) {
getElementWithI d = function(id) {
return document[id];
}
}
return getElementWithI d;
}();
Utils.addEvent( window, 'load', function() {
alert('ok');
Utils.getElemen tWithId("wordli st").innerHTM L = "";
Utils.getElemen tWithId("defini tion").innerHTM L = "line1<br>line2 ";
});
</script>
<table>
<tr>
<td><div id="wordlist" width="100%"></div></td>
<td bgcolor="#88888 8"></td>
<td valign="top"><d iv id="definition" ></div></td>
</tr
</table
</body>
</html>
Greets
Luke Matuszewski