Website Frontend _javascript-bom programming. 0002.JavaScriptLocation objects

Source: Internet
Author: User

Brief introduction:

Description: the Location object is the Window property and the document property, so it provides information and navigation capabilities for documents loaded in the current WINDOW.

Property name Property Description
Hash Returns the hash (#后跟零或多个字符) in the URL and returns an empty string if it does not contain a hash
Host Returns the server name and port number
Hostname Returns the server name without a port number
Href Returns the full URL of the currently loaded page as in location.tostring ()
Pathname Returns the directory or file name in the URL
Port Returns the port number of the server in the URL
Protocol Returns the protocol used by the page, usually HTTP or HTTPS
Search Returns the query string for the url, starting with a question mark
  Parse query string Function getquerystringargs () {    //  Remove the front of the query string? symbol      var qs = location.search?location.search.substring (1): '     //   Determine if there is a query string if there is a cut, otherwise return an empty array     var qsitems = qs.length?qs.split (' & ') :[]    var args = {}    //  traversing an array puts key-value pairs into the args object      qsitems.map (function (item, index, qsitems) {         var res = item.split (' = ')         //  Decodes a query string that may have been encoded         var key = decodeuricomponent ( itemarr[0]),            val =  decodeURIComponent (itemarr[1])         if (key) {             args[key] = val        }     })     //  Returns the alphanumeric object that contains the query string     return args}var args  = getquerystringargs () for (var key in args) {    console.log (key  +  '  ->  '  + args[key])}


Location Related:

Method name Method description
Assign (url) The current page opens a new URL and generates a record in the browser history that, like the settings window.location and Location.href effects, can be returned back to the previous page
Replace (url) The current page is replaced with a new URL page content that does not generate a record in the browser history, so it is not possible to return the previously replaced page by hind legs
Reload (force) If fore is true, attempts to force the current page to be refreshed from the server, or false to refresh the current page from the cache
After 1 seconds the page is replaced by Baidu SetTimeout (function () {location.replace (' http://www.baidu.com ')},1000)//intermittent Refresh under Page setinterval every 2 seconds ( function () {location.reload (true)}, 2000)

Description: code after the reload () call may or may not be executed, depending on factors such as network latency or system resources, so it is best to put reload () in the last line of code


This article is from the "ζ automated operation and maintenance Development Road ζ" blog, Please be sure to keep this source http://xmdevops.blog.51cto.com/11144840/1853795

Website Frontend _javascript-bom programming. 0002.JavaScriptLocation objects

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.