我正在尝试重新加载iframe,如下所示:
var frameObject = $('#myFrame');
var frameAsInDom = frameObject[0].contentWindow;
var currenctLocation = frameAsInDom.location;
frameObject.attr('src', 'about:blank');
frameObject.contents().remove(); // This was a desperate statement!!
frameObject.attr('src', currentLocation).load(function(){
alert('iframe reloaded');
});
问题是iframe的.load事件根本没有被触发。我没有在加载回调中获得警告。
答案 0 :(得分:5)
您正在混合事件的绑定和触发,
请参阅此代码:http://jsfiddle.net/BvQuk/1/
<强> HTML 强>
<iframe id="myFrame" src="http://google.com"></iframe><br/>
<input id="uxButton" type="button" value="Reload the frame" />
<强> JS 强>
$(document).ready(function() {
var iFrame = $('#myFrame');
iFrame.bind('load', function() { //binds the event
alert('iFrame Reloaded');
});
$('#uxButton').click(function() {
alert('onButtonClick OR onBeforeReload');
var newSrc = iFrame.attr('src') + '?c=' + Math.random(); //force new URL
iFrame.attr('src', newSrc); //changing the src triggers the load event
});
});
希望有所帮助。
答案 1 :(得分:1)
咄!! javascript错误.. currentLocation
未定义。 var currenctLocation