Window.location Application Example of JS

Source: Internet
Author: User

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


Window Location
The Window.location object can be written without using the window prefix.
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://)


Window location Href
The Location.href property returns the URL of the current page.
Instance
Returns the entire URL (of the current page):

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

View results: http://hovertree.com/hvtart/bjae/wvobi5ky.htm

Window location Pathname
The Location.pathname property returns the path name of the URL.
Instance
Returns the path name of the current URL:

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

View results: http://hovertree.com/hvtart/bjae/wvobi5ky.htm

Window location Assign
The Location.assign () method loads the new document.

You can view the contents of the document first: http://hovertree.com/texiao/js/6.htm

Instance
To load a new document:

<HTML><Head><Script>functionNewdoc () {window.location.assign ("http://hovertree.com/texiao/js/6.htm")}</Script></Head><Body><inputtype= "button"value= "Load New Document"onclick= "Newdoc ()"></Body></HTML>

Experience Effect: http://hovertree.com/hvtart/bjae/wvobi5ky.htm

Web Front End: http://www.cnblogs.com/jihua/p/webfront.html

Window.location Application Example of JS

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.