示例代码:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script>
function on_iframe_load() {
document.getElementById('iframe_a').onload = function() {
alert('Thanks for the visit!');
};
}
</script>
</head>
<body>
<iframe name="iframe_a" id="iframe_a"></iframe>
<a href="http://www.example.com/" target="iframe_a" onclick="on_iframe_load();">Go!</a>
</body>
</html>
它可以在所有主要的浏览器中正常运行,但 IE8(以及可能是之前的版本)无法理解它。 更新:我刚找到了一个解决方案,但我不确定它是否正确。请查看以下内容:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script>
var clicked = false;
function activate() {
clicked = true;
}
function pop() {
if (clicked) {
alert('Thanks for the visit!');
};
}
</script>
</head>
<body>
<iframe name="iframe_a" onload="pop();"></iframe>
<a href="http://www.example.com/" target="iframe_a" onclick="activate();">Go!</a>
</body>
</html>
attachEvent
,在其他浏览器中使用addEventListener
可以解决你的问题。 - Inferpse