views:

112

answers:

5

What does the following code return?

window.location.replace("/ak012/(S(sar23pq1ki5wo22qqmmidvie))/HTML/Page.ashx?ID=4")
+1  A: 

In javascript, it changes the browser's location (redirects) to the url specified, without adding it to the browser history. Introduced in Javascript 1.1. Documentation here.

ChristopheD
+1  A: 

"/ak012/(S(sar23pq1ki5wo22qqmmidvie))/HTML/Page.ashx?ID=4" - is a URL string window.location.replace(URL_STRING) - redirects to that URL

afftee
thanks have a nice day
streetparade
A: 

Literally, it will return undefined

In practice, it doesn't matter what it returns, since that function is the same as navigating to /ak012/(S(sar23pq1ki5wo22qqmmidvie))/HTML/Page.ashx?ID=4

Matt
+1  A: 

The replace() loads the specified URL over the current history entry. So when you use the replace method, the user cannot navigate to the previous URL by using Navigator's Back button.

The argument inside the replace is your url :

/ak012/(S(sar23pq1ki5wo22qqmmidvie))/HTML/Page.ashx?ID=4
Alex
+1  A: 

As Matt says, it returns undefined. It is a method for navigating to another document.

I just want to add to the answers here a warning that IE does not register a referrer when navigating using the document.location properties and methods.

My solution to this was to create a hidden A element in the document and programatically click that link.

Example HMTL:

<a href="http://www.stackoverflow.com" id="hidden-link" style="display: none"><!-- Blank --></a>

Example JavaScript:

var hiddenAElement = document.getElementById('hidden-link');

if ( document.all ) // Very simple IE detection.
{
    hiddenAElement.click();   
}
else
{
   document.location.href = hiddenAElement.href;
}
harald