基於對海姆的信息的評論,你想要什麼可以簡化爲:
$('#reload').click(function() {
$('#f1').attr('src', $('#f1').attr('src'));
return false;
});
或者
$('#reload').click(function() {
$('#f1')[0].contentWindow.location.reload(true);
return false;
});
但或許他的答案更符合您的需求。
UPDATE:
我使用我上面提供的方法放在一起的工作示例。我在一個頁面中顯示,顯示打印時間的另一個頁面。
的 HTML(time.html時):
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
The time is now <span id="time"></span>.
<script type="text/javascript">
$(document).ready(function() {
$('#time').html((new Date()).toString());
});
</script>
</body>
和父頁面HTML(test.html中):
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<iframe id="frame" src="file:///D:/Users/Cory/Desktop/time.html" width="500" height="250"></iframe>
<button id="reload">Refresh</button>
<script type="text/javascript">
$(document).ready(function() {
$('#reload').click(function() {
$('#frame').attr('src', $('#frame').attr('src'));
return false;
});
});
</script>
</body>
這一切正常,我在Firefox 3.6和IE 7.
這裏是我的代碼:
\t我更新但見@cory答案是好爲你 – 2010-08-24 11:55:41