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>
…
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.