按钮点击是否可以导致iframe中的事件? [英] Can a button click cause an event in iframe?
本文介绍了按钮点击是否可以导致iframe中的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我在Iframe旁边有一个按钮,并且iframe是一个下载链接。是否有可能当我点击外部按钮时,会点击iframe上的下载链接?
Let's say I have a button right next to an Iframe and in that Iframe is a download link. Is it possible that when I click the outside button, the download link on the iframe will be clicked?
http://jsfiddle.net/idude/9RQ3N/
<button type="button">Click Me!</button>
<iframe src="http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_a_download" height="400" width="800">
例如,在上面的jsfiddle链接中,我该如何制作它只需点击按钮即可下载w3图片?
For example, in the jsfiddle link above, how could I make it so that the w3 picture would be downloaded by just clicking the button?
提前致谢!
推荐答案
尝试(此模式)
$(function () {
var url = ["http://example.org"]; // `url`, e.g., `http://example.org`
var iframe = $("<iframe>", {
"id": "frame",
"width": "400px",
"height": "300px"
});
$.when($("body").append(iframe))
.then(function (b) {
var img = $("<img>", {
"id" : "frameimg",
"width": "400px",
"height": "300px",
}).css("background", "blue");
var a = $("<a>", {
"href" : url[0],
"html" : img
}).css("textDecoration", "none");
var button = $("<button>", {
"html": "click"
}).css("fontSize", "48px")
.one("click", function (e) {
$(b).find("#frame").contents()
.find("body a")
.get(0).click()
});
$(button).appendTo(b);
$(b).find("#frame").contents()
.find("body").html(a);
});
});
jsfiddle http://jsfiddle.net/guest271314/2x4xz/
jsfiddle http://jsfiddle.net/guest271314/2x4xz/
这篇关于按钮点击是否可以导致iframe中的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文