2009-12-18 61 views
4

我看到以下异常在FF 3.5.6:打电话时NS_ERROR_MALFORMED_URI在FF document.location.replace()

uncaught exception: [Exception... "The URI is malformed" nsresult: "0x804b000a (NS_ERROR_MALFORMED_URI)" location: "JS frame :: http://x :: refreshPage :: line 193" data: no] 

出现此错误调用document.location.replace时(“/相对/ url“)在iframe的父窗口上。

它也可以在FF2中重现,但IE8不会出现问题。

编辑:在相同的上下文下面的代码不具有问题:

document.location.reload(); 
+0

你用什么取代它?它可能以Firefox不能处理的格式错误的URI结束...... – sdwilsh 2009-12-18 06:23:46

+0

我用相对路径替换它。我注意到,如果我使用绝对路径,这个问题不存在。我想这可能是一个iframe安全限制。 – jthompson 2009-12-18 16:17:10

回答

5

我想出的解决方案是编写一个绝对URL并将其分配给window.location。重新加载()导致了内部重定向的一些问题。

function get_full_url(url_path) 
{ 
    var loc = window.location; 
    var url = "" + loc.protocol + "//" + loc.host + url_path; 
    return url; 
} 

function refresh_page_absolute(url_path) 
{ 
    window.location.href = get_full_url(url_path) 
} 
1
location.replace() 

是错误的。您必须将地址作为参数传递给replace方法。否则,你有效传入undefined,由于“URI格式不正确”消息表明,它不是有效的地址。

我不知道你要做什么...如果你想重新加载页面,你应该确实使用location.reload()。但'用(不)'替换当前位置的URI是没有意义的。

+0

我更新了问题,它被替换为相对URL。我只是表明我正在打电话。替换。 – jthompson 2009-12-18 16:16:11