示例代码:
<!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>