JavaScript gets the current URL path

Source: Internet
Author: User

1, assume the current page full address is: http://localhost:61768/Home/Index?id=2

//gets the URL of the current windowvarURL =window.location.href;//Results:http://localhost: 61768/home/index?id=2//gets the host name of the current windowvarHost =Window.location.host;//results: localhost:61768//gets the port of the current windowvarPort =Window.location.port;//results: 61768//gets the path of the current windowvarpathname =Window.location.pathname;//results:/home/index//gets the URL of the current documentvarURL =document. URL;//Results:http://localhost: 61768/home/index?id=2//Get ParametersvarSearch =Window.location.search;//results:? id=2

2. Jump out of the current window

// jump out of the current window and open a new window window.open ("http://www.baidu.com");

3. Document and Window

A Document object is implied by the file, and window is the object of a windows, which can have multiple document objects under a window.

So there is only one window.location.href under a window, there may be multiple document.url, document.location.href

Window.location.href and Document.location.href can be assigned, and then jump to other pages, document. URLs can only be read and cannot be assigned values.

Related article:C # request get URL

JavaScript gets the current URL path

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.