JavaScript Window Location

Source: Internet
Author: User

1.JavaScript Window Location

The Window.location object is used to obtain the address (URL) of the current page and redirect the browser to a new page.

1.1 Window Location

The window.location object can be written without using the window prefix. Some examples:

Some examples:

    • Location.hostname returns the domain name of the web host
    • Location.pathname returns the path and file name of the current page
    • Location.port returns the port of the web host (80 or 443)
    • Location.protocol returns the Web protocol used (HTTP///https://)

1.2Window location Href

The Location.href property returns the URL of the current page.

Returns the entire URL (of the current page):

<script>document.write (location.href); </script>

1.3Window location Pathname

The Location.pathname property returns the path name of the URL.

<script>document.write (location.pathname); </script>

1.4Window location Assign

The Location.assign () method loads the new document.

function Newdoc ()  {  window.location.assign (" http://www.w3cschool.cc " )  }</script>"button" Value="Load New document" onclick="newdoc ()" ></body>

2.JavaScript Window History

The Window.history object contains the history of the browser.

2.1 Window history

The window.history object can be written without using the window prefix.

To protect user privacy, there are limitations to how JavaScript accesses the object.

Some methods:

    • History.back ()-Same as clicking Back button in browser
    • History.forward ()-Same as clicking the Forward button in the browser

2.2Window history back

The History.back () method loads the previous URL in the History list.

This is the same as clicking the Back button in the browser:

function GoBack ()  {  window.history.back ()  }</ Script>"button" value="back  " onclick="goBack ()"></body>

JavaScript Window Location

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.