...

View Full Version : simple innerHTML in Opera



kyvinh
06-01-2004, 09:49 AM
Hi,
I'm trying to use the innerHTML property in Opera 7.5. But even a very simple script like the following does not work:



<iframe id="text" width="250" height="50" frameborder="0"></iframe>

<script>
document.getElementById('text').innerHTML='<center><b>YAHOO</b> </center>';
</script>


Anybody knows why?

-- Kyvinh

glenngv
06-01-2004, 10:51 AM
That would not work in any browser either. iframe is also a window object just like frame.

Try this:

<iframe id="text" src="about:blank" width="250" height="50" frameborder="0"></iframe>

<script>
document.getElementById('text').document.body.innerHTML='<center><b>YAHOO</b></center>';
</script>

liorean
06-01-2004, 12:45 PM
Just an addition to that: You should NEVER, EVER use the character sequence </ in an embedded script. Use <\/ instead.

kyvinh
06-01-2004, 07:47 PM
Try this:
<iframe id="text" src="about:blank" width="250" height="50" frameborder="0"></iframe>

<script>
document.getElementById('text').document.body.innerHTML='<center><b>YAHOO</b></center>';
</script>


When trying that, Opera gives me this error:
Inline script thread
Error:
name: ReferenceError
message: Security error: attempted to read protected variable
Is there any other way to change the "innerHTML" in modern browsers? Is this just Opera's whims? :confused:

sad69
06-01-2004, 07:57 PM
Did you read liorean's post?

Try:


<iframe id="text" src="about:blank" width="250" height="50" frameborder="0"></iframe>

<script>
document.getElementById('text').document.body.innerHTML='<center><b>YAHOO<\/b><\/center>';
</script>

liorean
06-01-2004, 08:03 PM
JavaScript is not allowed to reach across domains. You are not only trying to reach across domains, you are trying to reach another protocol that resides on the client. Allowing homepages access to it would be a considerable security risk, one already known to exist and having been exploited to steal username:password tuples from out-of-domain cookies in iew.

kyvinh
06-02-2004, 02:12 AM
OK, thanks everybody. I guess Lioran is right and I just cannot do that.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum