/    Sign up×
Community /Pin to ProfileBookmark

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
[url]http://www.noreality.net[/url]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisApr 27.2003 — 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>[/quote]

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;[/quote]should bedocument.getElementById('talkdest').innerHTML = window.top.frames['talksrc'].innerHMTL;
Copy linkTweet thisAlerts:
@Xer0authorApr 27.2003 — 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
  • Copy linkTweet thisAlerts:
    @gil_davisApr 27.2003 — [b]Security error: attempted to read protected variable[/b][/quote]That 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.
    [b]Isn't 'window.top' assumed?[/b][/quote]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.
    Copy linkTweet thisAlerts:
    @Xer0authorApr 28.2003 — lol, that assume thing is good.

    I've given up on the above method.

    I'm trying a different approach:
    <i>
    </i>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?
    Copy linkTweet thisAlerts:
    @gil_davisApr 28.2003 — Since I don't have Opera, I can only suggest you try this yourself:&lt;script&gt;
    var e = document.createElement("script");
    for (var i in e) alert(i + " = " + e[i]);
    &lt;/script&gt;
    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");
    Copy linkTweet thisAlerts:
    @Xer0authorApr 29.2003 — I have got it working with the following code:
    <i>
    </i>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.
    ×

    Success!

    Help @Xer0 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.3,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...