Class Location
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The Location interface represents the location (URL) of the object it is linked to. Changes done on it are reflected on the object it relates to. Both the Document and Window interface have such a linked Location, accessible via Location and Location respectively.
[Value("Location")]
public class Location
- Inheritance
-
Location
- Inherited Members
Remarks
-Two Location properties: Location and Location.
-URL manipulation interfaces: URL and URLSearchParams.
Constructors
Location()
public Location()
Properties
AncestorOrigins
The ancestorOrigins read-only
property of the Location interface is a static
DOMStringList containing, in reverse order, the origins of all ancestor
browsing contexts of the document associated with the given Location
object.
[Value("ancestorOrigins")]
public DOMStringList AncestorOrigins { get; }
Property Value
Remarks
You can use location.ancestorOrigins in the script for a document to
determine, for example, whenever the document is being framed by a site which you don't
expect it to be framed by. You can also use it to vary the behavior of the document
based on what site or list of sites is framing it.
Hash
The hash property of the Location interface is a string containing a "#" followed by the fragment identifier of the location URL. If the URL does not have a fragment identifier, this property contains an empty string, "".
[Value("hash")]
public string Hash { get; set; }
Property Value
- string
A string.
Remarks
See Hash for more information.
Host
The host property of the Location interface is a string containing the host, which is the Hostname, and then, if the {{glossary("port")}} of the URL is nonempty, a ":", followed by the Port of the URL. If the URL does not have a hostname, this property contains an empty string, "".
[Value("host")]
public string Host { get; set; }
Property Value
- string
A string.
Remarks
See Host for more information.
Hostname
The hostname property of the Location interface is a string containing either the {{glossary("domain name")}} or {{glossary("IP address")}} of the location URL. If the URL does not have a hostname, this property contains an empty string, "". IPv4 and IPv6 addresses are normalized, such as stripping leading zeros, and domain names are converted to IDN.
[Value("hostname")]
public string Hostname { get; set; }
Property Value
- string
A string.
Remarks
See Hostname for more information.
Href
The href property of the Location
interface is a stringifier that returns a string containing the whole
URL, and allows the href to be updated.
[Value("href")]
public string Href { get; set; }
Property Value
- string
A string.
Remarks
Setting the value of href navigates to the provided URL. If you
want redirection, use Locationreplace. The difference from setting the href property value is that when using the location.replace() method, after navigating to the given URL, the current page will not be saved in session history — meaning the user won't be able to use the back button to navigate to it.
Origin
The origin read-only property of the Location interface returns a string containing the Unicode serialization of the origin of the location's URL.
[Value("origin")]
public string Origin { get; }
Property Value
- string
A string.
Remarks
The exact structure varies depending on the type of URL:
For all other cases, the string "null" is returned.
See Origin for more information.
-Window.origin
-origin glossary term
Pathname
The pathname property of the Location
interface is a string containing the path of the URL for the location. If there is no path, pathname will be empty: otherwise, pathname contains an initial '/' followed by the path of the URL, not including the query string or fragment.
[Value("pathname")]
public string Pathname { get; set; }
Property Value
- string
A string.
Remarks
Port
The port property of the Location interface is a string containing the port number of the location's URL. If the port is the default for the protocol (80 for ws: and http:, 443 for wss: and https:, and 21 for ftp:), this property contains an empty string, "".
[Value("port")]
public string Port { get; set; }
Property Value
- string
A string.
Remarks
This property can be set to change the port of the URL. If the URL has no Host or its scheme is file:, then setting this property has no effect. It also silently ignores invalid port numbers.
See Port for more information.
Protocol
The protocol property of the Location interface is a string containing the protocol or scheme of the location's URL, including the final ":".
[Value("protocol")]
public string Protocol { get; set; }
Property Value
- string
A string.
Remarks
This property can be set to change the protocol of the URL. A ":" is appended to the provided string if not provided. The provided scheme has to be compatible with the rest of the URL to be considered valid.
See Protocol for more information.
Search
The search property of the Location interface is a search string, also called a query string, that is a string containing a "?" followed by the parameters of the location's URL. If the URL does not have a search query, this property contains an empty string, "".
[Value("search")]
public string Search { get; set; }
Property Value
- string
A string.
Remarks
This property can be set to change the query string of the URL. When setting, a single "?" prefix is added to the provided value, if not already present. Setting it to "" removes the query string.
The query is Percent-encoding when setting but not percent-decoded when reading.
Modern browsers provideURLSearchParams
andURL.searchParams
to make it easy to parse out the parameters from the querystring.
See Search for more information.
Methods
Assign(string)
The assign() method of the Location
interface causes the window to load
and display the document at the URL specified. After the navigation occurs, the user can
navigate back to the page that called Location.assign() by pressing the "back" button.
[Value("assign")]
public GlobalObject.Undefined Assign(string url)
Parameters
urlstring
Returns
Remarks
-The Location interface it belongs to.
-Similar methods: Replace(string) and
Reload().
Reload()
The reload() method of the Location interface reloads the current URL, like the Refresh button.
[Value("reload")]
public GlobalObject.Undefined Reload()
Returns
Remarks
-The Location interface it belongs to.
-Similar methods: Assign(string) and
Replace(string).
Replace(string)
The replace() method of the Location
interface replaces the current resource with the one at the provided URL. The difference
from the Assign(string) method is that after usingreplace() the current page will not be saved in session History,
meaning the user won't be able to use the back button to navigate to it.
Not to be confused with the String method StringPrototypeReplace.
[Value("replace")]
public GlobalObject.Undefined Replace(string url)
Parameters
urlstring
Returns
Remarks
-The Location interface it belongs to.
-Similar methods: Assign(string) and
Reload().