DarrenBrothers
07-05-2003, 04:03 PM
Hi, all.
I have some existing Javascript code that is used on our website (http://www.hillscapital.com/) to dynamically update the contents of a DIV container. It places an external HTML file into the DIV container dynamically (without having to reload the entire page).
This allows us to keep certain portions of the page loaded all the time (our menu, quotes ticker and news ticker), while dynamically updating the content that is shown in the main part of the page.
Unfortunately, it is not cross-browser compatible, and I want it to be. It only works for IE 5 and higher right now.
Here's the code as it is now:
<!-- Start Dynamic Content Code
var doAll = (document.all!=null)
function getCSSPElement(id) {
// Return the positioned element with the specified ID
if(document.getElementById)
return document.getElementById(id)
else if (doAll)
return document.all[id]
else
return document.layers[id]
}
function checkIFrame(destID) {
var iframe = document.frames[destID+"target"]
if (iframe==null) {
document.body.insertAdjacentHTML("beforeEnd","<IFRAME STYLE='width: 0pt; height: 0pt' NAME='"+destID+"target' SRC='' ></IFRAME>")
iframe = document.frames[destID+"target"]
}
return iframe
}
function pollIFrame(destID) {
var destFrame = checkIFrame(destID)
if (destFrame.document.readyState=='complete') {
var el1 = getCSSPElement(destID)
el1.innerHTML = destFrame.document.body.innerHTML
} else
setTimeout("pollIFrame('"+destID+"')",200)
}
function updateContents(destID, src) {
var el1 = getCSSPElement(destID)
if (doAll) {
destFrame = checkIFrame(destID)
destFrame.location.href = src
setTimeout("pollIFrame('"+destID+"')",200)
}
else
el1.src = src
}
function update(destID, src) {
if (src=="none") {
var el1 = getCSSPElement(destID)
if (doAll)
el1.innerHTML = ""
else {
el1.document.open()
el1.document.write("")
el1.document.close()
}
}
else
updateContents(destID, src)
}
function openPage(page) {//Example javascript:openPage('http://www.yahoo.com/');
window.open(page , "external" , "toolbar=yes, location=no, status=yes, menubar=yes, resizable=yes , scrollbar=yes");
}
// End Dynamic Content Code -->
It is called like this:
update('content','intro.htm');
Where:
update = function name
content = DIV ID
intro.htm = external HTML file that will be placed into the DIV with the appropriate ID (in this case, 'content').
I contacted Eddie Traversa of the DHTMLNirvana.com website, and this is what he said:
"The problem you have with your script, is that you are using insertadjacentHTML which is IE specific code. If you use createElement and then use setAttribute to define the iframes properties then that should work in a cross browser fashion for you. "
Unfortunately, I don't know how to do what he suggested.
Can anyone help?
Thanks,
Darren Brothers
darrenbrothers@yahoo.com
I have some existing Javascript code that is used on our website (http://www.hillscapital.com/) to dynamically update the contents of a DIV container. It places an external HTML file into the DIV container dynamically (without having to reload the entire page).
This allows us to keep certain portions of the page loaded all the time (our menu, quotes ticker and news ticker), while dynamically updating the content that is shown in the main part of the page.
Unfortunately, it is not cross-browser compatible, and I want it to be. It only works for IE 5 and higher right now.
Here's the code as it is now:
<!-- Start Dynamic Content Code
var doAll = (document.all!=null)
function getCSSPElement(id) {
// Return the positioned element with the specified ID
if(document.getElementById)
return document.getElementById(id)
else if (doAll)
return document.all[id]
else
return document.layers[id]
}
function checkIFrame(destID) {
var iframe = document.frames[destID+"target"]
if (iframe==null) {
document.body.insertAdjacentHTML("beforeEnd","<IFRAME STYLE='width: 0pt; height: 0pt' NAME='"+destID+"target' SRC='' ></IFRAME>")
iframe = document.frames[destID+"target"]
}
return iframe
}
function pollIFrame(destID) {
var destFrame = checkIFrame(destID)
if (destFrame.document.readyState=='complete') {
var el1 = getCSSPElement(destID)
el1.innerHTML = destFrame.document.body.innerHTML
} else
setTimeout("pollIFrame('"+destID+"')",200)
}
function updateContents(destID, src) {
var el1 = getCSSPElement(destID)
if (doAll) {
destFrame = checkIFrame(destID)
destFrame.location.href = src
setTimeout("pollIFrame('"+destID+"')",200)
}
else
el1.src = src
}
function update(destID, src) {
if (src=="none") {
var el1 = getCSSPElement(destID)
if (doAll)
el1.innerHTML = ""
else {
el1.document.open()
el1.document.write("")
el1.document.close()
}
}
else
updateContents(destID, src)
}
function openPage(page) {//Example javascript:openPage('http://www.yahoo.com/');
window.open(page , "external" , "toolbar=yes, location=no, status=yes, menubar=yes, resizable=yes , scrollbar=yes");
}
// End Dynamic Content Code -->
It is called like this:
update('content','intro.htm');
Where:
update = function name
content = DIV ID
intro.htm = external HTML file that will be placed into the DIV with the appropriate ID (in this case, 'content').
I contacted Eddie Traversa of the DHTMLNirvana.com website, and this is what he said:
"The problem you have with your script, is that you are using insertadjacentHTML which is IE specific code. If you use createElement and then use setAttribute to define the iframes properties then that should work in a cross browser fashion for you. "
Unfortunately, I don't know how to do what he suggested.
Can anyone help?
Thanks,
Darren Brothers
darrenbrothers@yahoo.com