> For the complete documentation index, see [llms.txt](https://sec88.0x88.online/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sec88.0x88.online/programming/javascript-js/window.location-object.md).

# window\.location object

In JavaScript, the `window.location` object has several properties that you can use to get information about the current URL or manipulate it. Here are some key properties and methods:

1. **window\.location.hash**: Returns the anchor part of a URL, including the hash sign (`#`).

   ```javascript
   console.log(window.location.hash); // e.g., "#section1"
   ```
2. **window\.location.href**: Returns the entire URL of the current page.

   ```javascript
   console.log(window.location.href); // e.g., "https://www.example.com/page?query=123#section1"
   ```
3. **window\.location.protocol**: Returns the protocol scheme of the URL, including the final colon (`:`).

   ```javascript
   console.log(window.location.protocol); // e.g., "https:"
   ```
4. **window\.location.host**: Returns the host (hostname and port) of the URL.

   ```javascript
   console.log(window.location.host); // e.g., "www.example.com:80"
   ```
5. **window\.location.hostname**: Returns the domain name of the web host.

   ```javascript
   console.log(window.location.hostname); // e.g., "www.example.com"
   ```
6. **window\.location.port**: Returns the port number of the URL.

   ```javascript
   console.log(window.location.port); // e.g., "80"
   ```
7. **window\.location.pathname**: Returns the path of the URL.

   ```javascript
   console.log(window.location.pathname); // e.g., "/page"
   ```
8. **window\.location.search**: Returns the query string of the URL, including the question mark (`?`).

   ```javascript
   console.log(window.location.search); // e.g., "?query=123"
   ```

#### Methods

1. **window\.location.assign(url)**: Loads the resource at the URL provided.

   ```javascript
   window.location.assign('https://www.example.com');
   ```
2. **window\.location.replace(url)**: Replaces the current document with the one at the URL provided. This method does not create a new entry in the browser's history.

   ```javascript
   window.location.replace('https://www.example.com');
   ```
3. **window\.location.reload(forceReload)**: Reloads the current URL. If `forceReload` is true, the page will be reloaded from the server.

   ```javascript
   window.location.reload(); // Reloads the page from the cache
   window.location.reload(true); // Reloads the page from the server
   ```

These properties and methods are useful for manipulating the URL or redirecting the user to a different page.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sec88.0x88.online/programming/javascript-js/window.location-object.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
