Click to See Complete Forum and Search --> : Opera and IFRAME
I am having a problem accessing the innerHTML of an IFRAME in opera. I have read bits and pieces saying that this property does not exist in Opera, but is there a workaround? The code I am working with is thus:
<div id='talkdest' class='item'></div>
<iframe id='talksrc' name='talksrc'></iframe>
function refresh() {
____frames['talksrc'].location.href = 'include/talksrc.php?random=' + Math.round(Math.random() * 10000);
_____document.getElementById('talksrc').innerHTML = frames['talksrc'].innerHMTL;
_____// The above line is what I am having problems with
____setTimeout("refresh()", 5000);
}
Ideally I need a cross-browser solution, but Opera is the most important to get working.
- Xavier
http://www.noreality.net
gil davis
04-26-2003, 09:39 PM
According to their website, Opera 7 does indeed support both innerHTML and iframe. See http://www.opera.com/docs/specs/index.dml for more information.
<div id='talkdest' class='item'></div>
<iframe id='talksrc' name='talksrc'></iframe>
So, are you trying to load something into the IFRAME and then move it to the DIV? If so,
document.getElementById('talksrc').innerHTML = frames['talksrc'].innerHMTL;should bedocument.getElementById('talkdest').innerHTML = window.top.frames['talksrc'].innerHMTL;
Sorry for my careless posting, I have tried what you mentioned, I get the following error.
Inline script thread
Error:
name: ReferenceError
message: Security error: attempted to read protected variable
IE returns 'undefined'.
Thanks for the opera link, I will give it a closer look.
On another trivial matter, Isn't 'window.top' assumed?
- Xavier
http://www.noreality.net
gil davis
04-27-2003, 10:35 AM
Security error: attempted to read protected variableThat usually indicates an attemt to access data from a foreign domain, which is a security violation. You are not allowed to access data from a different domain using Javascript. It is a security violation.
Isn't 'window.top' assumed?Are you familiar with the definition of "assume"? It makes an ASS out of U and ME. In my experience, only IE is loose enough to allow you to get away with such short cuts. There are places where it would be required, and since I did not know the rest of your document's structure, I gave you the fullest syntax I could think of in order to give you the best chance of making Opera work. I'm no Opera expert, but I know that such an assumption will give Netscape heartburn, and possibly Opera as well.
lol, that assume thing is good.
I've given up on the above method.
I'm trying a different approach:
function dhtmlLoadScript(url) {
____window.top.frames['talksrc'].location.href = 'include/talksrc.php?random=' + Math.round(Math.random() * 10000);
____var e = document.createElement("script");
_e.src = url;
_e.type="text/javascript";
_document.getElementsByTagName("head")[0].appendChild(e);
_setTimeout("dhtmlLoadScript('include/talk.js?random=' + Math.round(Math.random() * 10000))", 2000);
}
dhtmlLoadScript('include/talk.js?random=' + Math.round(Math.random() * 10000));
talk.js is rewritten by talksrc.php everytime it is called.
This method works in IE (yay!), but Opera raise a syntax error on the 'e.type = ...'. If I comment it out I get other syntax errors about e not existing. Does Opera not like createElement("script")? Any ideas?
gil davis
04-28-2003, 06:46 AM
Since I don't have Opera, I can only suggest you try this yourself:<script>
var e = document.createElement("script");
for (var i in e) alert(i + " = " + e[i]);
</script>See if one of the alerts saystype = You will see all the attributes that the script tag supports (I know it's a pretty long list in NS 6 and IE 5.5).
Perhaps you need to use the real DOM method setAttribute().e.setAttribute("type", "text/javascript");
I have got it working with the following code:
function dhtmlLoadScript(url) {
_window.top.frames['talksrc'].location.href = 'include/talksrc.php?random=' + Math.round(Math.random() * 10000);
_setTimeout("dhtmlLoadScript('include/talk.js?random=' + Math.round(Math.random() * 10000))", 3000);
}
dhtmlLoadScript('include/talk.js?random=' + Math.round(Math.random() * 10000));
And placing this in into the IFRAME inside script tags:
window.parent.document.getElementById('talkdest').innerHTML = "content";
Thanks for all your help.