【发布时间】:2015-12-20 08:17:09
【问题描述】:
这不是不可能的,但我已经花了很多时间在这里寻找答案并尝试组合。
我有多个由代码生成的 iframe,每个 iframe 都有一个唯一的 ID。我希望能够通过按钮或双击来阻止某些 iframe 加载。
<iframe id='kwjef' src='kwjef.html'
onClick="stop_iframe($(this).attr('id'));" />
<iframe id='wefhj' src='wefhj.html'
onClick="stop_iframe($(this).attr('id'));" />
<iframe id='yhvem' src='yhvem.html'
onClick="stop_iframe($(this).attr('id'));" />
function stop_iframe(id) {
window.frames[0].stop(); /* works to stop first iframe */
window.frames[1].stop(); /* works to stop second iframe */
window.getElementById(id).stop(); /* throws error */
$('iframe#'+id).stop(); /* throws error */
}
如何通过 id 正确选择 iframe 以便调用 stop()?
编辑(thnxz Vicky Gonsalves):
function stop_iframe(id) {
document.getElementById(id).src="#";
}
这可以使 iframe 空白,但不能真正停止请求,window.frames[0].stop();确实会停止请求(例如浏览器中的停止按钮)。
【问题讨论】:
标签: javascript iframe jquery-selectors selector