【发布时间】:2014-11-21 04:54:43
【问题描述】:
当我使用 faroo 搜索并移动到其他网页时,我正在使用 iframe 将 faroo.com 作为默认 src 加载到框架中。但仍然在 iframe src 中显示 faroo.com,我只想捕获具有在 iframe 中加载
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(function(){
$('#frameid').load(function(){
var z=$('#frameid').attr('src');
console.log('hi '+z);
});
$('#clicked').on('click', function(){
$('#frameid').attr('src', 'http://www.faroo.com/');
});
});
</script>
</head>
<body>
<iframe width="100%" height="500px" id="frameid" src="" name="iframe_a" ></iframe>
<p><input type="button" value="click me!" id="clicked"></p>
</body>
</html>
console.log 的 o/p 始终是 faroo.com,而不是当前加载的网站
【问题讨论】:
-
如果您正在寻找 iframe 的“父”页面的 url,请参阅stackoverflow.com/q/3420004/32453
标签: javascript jquery html