Vishal Mokal
Vishal Mokal

Reputation: 800

Calling jquery function of child page displayed in iframe from parent page

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

Answers (2)

Vishal Mokal
Vishal Mokal

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

Kundan Singh Chouhan
Kundan Singh Chouhan

Reputation: 14302

Try this instead:

$('#iframeID')[0].contentWindow["callfontOpenSans"]();

Hope this will help.

Upvotes: 1

Related Questions