开发者

NS_ERROR_MALFORMED_URI in FF when calling document.location.replace()

I'm seeing the following exception in FF 3.5.6:

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

This error occurs when calling document.location.replace("/relative/url") on the parent window of an iframe.

It's also reproducible in FF2, but IE8 doesn't exhibit the problem.

EDIT: The following code in the same con开发者_如何学运维text doesn't have the problem:

document.location.reload();


The solution I came up with for this was to compose an absolute URL and assigning it to window.location. Reload() caused some problems with internal redirects.

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)
}


location.replace()

is an error. You must pass an address into the replace method as an argument. Otherwise you're effectively passing in undefined, which as the “URI is malformed” message would suggest, is not a valid address.

I don't know what you're trying to do... if you want to reload the page you should indeed use location.reload(). But ‘replace the current location's URI with (nothing)’ is meaningless.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜