我使用jQuery的動畫一些DOM元素,但我希望頁面動畫完成時重新加載,所以我想這:JavaScript在關閉/匿名函數中重新加載頁面?
function childDisablePopup()
{
$("#popup2",window.parent.document).animate({
width: "0px",
marginLeft: 0
}, "fast",
function()
{
$("#popup2",window.parent.document).animate({
height: "0px",
marginTop: 0
}, "fast",
function()
{
$("#backgroundPopup",window.parent.document).fadeOut("fast",
function()
{
$("#popup2",window.parent.document).remove();
window.location.reload(true);
});
});
});
}
然而,當動畫完成的,而不是重新加載頁面,我得到這個錯誤:
uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMLocation.reload]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: etc...]
這是怎麼回事?頁面重新加載不能放在函數中(){} closure?
注意:瀏覽器:firefox 3.6.8。
觀衆的瀏覽器:Firefox 3以上,鉻,Safari 5以上
注:我也嘗試過window.location.reload(true);
其返回同樣的錯誤,我試圖window.location.href=window.location.href
其返回:
uncaught exception: [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMLocation.href]" nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)" location: "JS frame :: etc...]
'window.location.href'可能不會接受賦值。試試'window.location.replace(window.location.href);'?我開始傾向於最初的想法,那就是試圖與父窗口的DOM進行交互......坦率地說,我很難過。 – 2010-08-04 18:44:31
我似乎無法重現異常。 (我也使用Firefox 3.6.8)除了我沒有在選擇器中使用'window.parent.document',所以它可以是你的腳本中的其他地方。 – casablanca 2010-08-04 19:04:57
好吧,這很奇怪,我甚至不能做'alert(window.location.href)'而不拋出相同的異常。 – 2010-08-04 22:31:34