Reputation: 800
I've got a page where clicking a div calls a function:
$("#fontOpenSans").on("click", function(event) {
event.stopPropagation();
$("#dlVersion *").css("font-family", $(this).css("font-family"));
localStorage.font_family = $(this).css("font-family");
});
I am showing this page in iframe now i want to call same function from out side of this page (From the page in which iframe is placed).
If I declare it like this:
function callfontOpenSans() {
event.stopPropagation();
$("#dlVersion *").css("font-family", $(this).css("font-family"));
localStorage.font_family = $(this).css("font-family");
}
Then I can call it like this:
$('#iframeID').contentWindow.callfontOpenSans();
How would I call a function written in the first way from outside the page (i.e. the parent page)? Thanks in advance.
Upvotes: 0
Views: 1931
Reputation: 800
Hello friends i got answer for my question
$('#iframeId').contents().find('#fontOpenSans').click();
solved my problem thanks
will work when both pages are on same domain
Upvotes: 0
Reputation: 14302
Try this instead:
$('#iframeID')[0].contentWindow["callfontOpenSans"]();
Hope this will help.
Upvotes: 1