Javascript 从父页面调用iframe中显示的子页面的jquery函数
我有一个页面,点击一个div调用一个函数:Javascript 从父页面调用iframe中显示的子页面的jquery函数,javascript,jquery,html,iframe,Javascript,Jquery,Html,Iframe,我有一个页面,点击一个div调用一个函数: $("#fontOpenSans").on("click", function(event) { event.stopPropagation(); $("#dlVersion *").css("font-family", $(this).css("font-family")); localStorage.font_family = $(this).css("font-family"); }); 我正在iframe中显示这个页面
$("#fontOpenSans").on("click", function(event) {
event.stopPropagation();
$("#dlVersion *").css("font-family", $(this).css("font-family"));
localStorage.font_family = $(this).css("font-family");
});
我正在iframe中显示这个页面,现在我想从这个页面的外侧(从放置iframe的页面)调用相同的函数
如果我这样声明:
function callfontOpenSans() {
event.stopPropagation();
$("#dlVersion *").css("font-family", $(this).css("font-family"));
localStorage.font_family = $(this).css("font-family");
}
$('#iframeID').contentWindow.callfontOpenSans();
那么我可以这样称呼它:
function callfontOpenSans() {
event.stopPropagation();
$("#dlVersion *").css("font-family", $(this).css("font-family"));
localStorage.font_family = $(this).css("font-family");
}
$('#iframeID').contentWindow.callfontOpenSans();
如何从页面外部(即父页面)调用以第一种方式编写的函数?提前感谢。试试这个:
$('#iframeID')[0].contentWindow["callfontOpenSans"]();
希望这会有所帮助。朋友们好,我的问题得到了答案
$('#iframeId').contents().find('#fontOpenSans').click();
解决了我的问题
谢谢
当两个页面都在同一个域上时,将起作用
嗨,昆丹,谢谢你的回复。我知道用这种方法我可以调用函数,但是你调用的是一个函数,我想用第一种方法调用函数declare