开发者

Click event in iframe

I'm trying to append the url of the parent page an iframe is located in based on the current url within the iframe.

This is all taking place on the same domain, so I don't think there should be any security issues.

EDIT:

My code now looks like the following:

function locator_url() {

var iframeUrl = alert(document.getElementById("dealer-        locator").documentWindow.location.href);

var iframeUrlSplit = iframeUrl.split('/locator/');

window.location.hash = '#' + iframeUrlSplit[1];

};


$(document).ready(function(){

    document.getElementById("dealer-locator").contentWindow.onload = locator_url(); 
});

Now the default src for the iframe is http://localhost/meade/locator/ The page the iframe is on is http://localhost/meade/dealerlocator/

The code works for the initial page load, the parent url is appended to localhost/meade/dealerlocator/#

However, when I click a link inside the iframe the parent url doesn't change, even though the href value in the iframe has.

The parent url should have it's hash updated to something like:

localhost/meade/dealerlocator/#results_list.php?showonly=US&tab=US&zip=&distance=开发者_StackOverflow10&state=&city=&name=

But that's not happening.

What am I missing?


Did you try:

document.getElementById("dealer-locator").contentWindow.onload = locator_url;


Well, if you need click events in your iframe, then you could do it this way:

<a href="http://www.car.com" onClick="parent.locator_url(); return false;">Car.com</a>

Then locator_url() gets called in the parent page. Same goes for using load events (I mean, load events that occur in the iframe context).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜