/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Get the filename of .scr in IFrame

Should be easy, but I’m not getting results. I’m trying to get the filename of the scr= documentname of an IFRAME. The IFRAME is the child of the top-level document, (happens to be a .php file if that matters, but the .php code is nowhere near this). The JS is called from the top-level document.

The IFRAME is defined with

[CODE]<iframe src=”../../photos/index.htm” name=”galleryFrame” …*[/CODE]

The IFRAME displays the HTML source file just fine.

I’ve tried:

document.write(“Hello World”)
document.write(document.galleryFrame.document.url)
document.write(document.frames[‘galleryFrame’].document.url)
document.write(document.frames[‘galleryFrame’].document.url)
document.write(parent.frames[‘galleryFrame’].document.url) (didn’t expect this to work, since this is the top-level document)

Where I’m eventually hoping to get to with this is:

document.write(document.frames[‘galleryFrame’].document.images(‘thumb1’).src.url

“Hello World” is displaying on the page just fine.

  • * I’ve tried ID=”galleryFrame” also, and tried to retrieve it with getElementByID(‘galleryFrame’), but that doesn’t seem to work either.
  • Thanks,

    to post a comment
    JavaScript

    5 Comments(s)

    Copy linkTweet thisAlerts:
    @mrhooMar 13.2007 — when you call document.write on the top window it will replace the current page, including the iframe.

    try using an alert in the parent window:

    alert(top.document.getElementsByTagName('iframe')[0].src)
    Copy linkTweet thisAlerts:
    @mousebearauthorMar 14.2007 — I found this really good resource on this subject: http://www.quirksmode.org/js/iframe.html

    document.write didn't seem to do anything other than print to the page.

    This seemed to be the answer for my particular browser (IE7):

    document.write(frames('galleryFrame').location.href)

    I'm still going to try to find out how to find the source of one of the named images within the HTML inside the IFRAME.
    Copy linkTweet thisAlerts:
    @mousebearauthorMar 14.2007 — OK, maybe I should have clarified: The IFRAME has a source, which has a URL returned by the code above. That source is an HTML file, which has many named images inside it. However, the images are placed inside Anchor tags (which don't currently have names, but presumably could), where onclick events also reside. So how do I retrieve the filename of the IMG source within the anchor within the html file within the iframe? Sounds like the spider which ate the fly...
    Copy linkTweet thisAlerts:
    @mousebearauthorMar 15.2007 — Through a lot of slow troubleshooting, I've gotten the following to work:


    [CODE]alert(document.frames('galleryFrame').document.images('thumb2').src);[/CODE]

    There's the oddest thing though, This doesn't work unless I put the following line above it:

    [CODE]alert("hello");[/CODE]

    Does anyone have an idea of what is going on here?

    Thanks,
    Copy linkTweet thisAlerts:
    @mousebearauthorMar 15.2007 — This question has evolved into something very different than the orignal topic. I'm going to move it to a new thread...
    ×

    Success!

    Help @mousebear 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.19,
    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: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

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