/    Sign up×
Community /Pin to ProfileBookmark

Problem About URL Delecting of Another Frame In a Page

I’m a new in JavaScript, so I am afraid this question is rather too easy…

I am working on a page with two frames, one is showing a website (Frame 1), another showing a navigation (Frame 2, script is in this frame). I want to display the URL of Frame 1 (The page in Frame 1 contains several links, and the URL I want to display is the real-time one. Frame.src seems not working after I clicked on a link in Frame 1, it showed the old URL.) in Frame 2 when clicking a button. I wrote code like this:

[CODE]

<script type=”text/javascript”>
function geturl()
{
alert(parent.document.getElementById(“frame2”).contentDocument.URL);
}
</script>

[/CODE]

But it seems always fail if the page in Frame 1 is on another domain. (I’m not sure about the reason. I have already done plenty of experiment about this in several domains and it always fail when the page in Frame 1 is on another domain, even a subdomain. )
(I use Mozilla Firefox 3.0.10 for test.)
1. Why is this happening?
2. Are there any better ways to detect URL of another frame? Seems IE does not support “contentDocument”.
3. Are there any “events” when a page in Frame change, which means, after I click on a link in the Frame 1, will there be any “events” happening?

Thanks.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangApr 30.2009 — 
  • 1. Both documents must be in the same domain to obtain any information.


  • 2. top.document.getElementById('frame2').src


  • 3. onload event in the document in the frame.
  • Copy linkTweet thisAlerts:
    @RichardGvauthorMay 01.2009 — Thanks a lot.

    However:
    [LIST]
  • [*]In the first post I said:

    ...(The page in Frame 1 contains several links, and the URL I want to display is the real-time one. Frame.src [COLOR="Olive"][I](I mean here "top.document.getElementById('frame2').src") [/I][/COLOR]seems not working after I clicked on a link in Frame 1, it showed the old URL.)...
    [/QUOTE]

    So the second answer actually does not fit my need. But thanks anyway.

  • [*]About this answer:
    onload event in the document in the frame. [/QUOTE]
    I cannot modify the content within Frame 2 since it's a forum within using PHP...

  • [/LIST]
    ×

    Success!

    Help @RichardGv 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.5,
    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,
    )...