Why is Window.location.search empty?

Source: Internet
Author: User

1, what is window.location? Example

Url:http://b.a.com:88/index.php?name=kang&when=2011#first

Properties meaning value
Protocol Agreement "http:"
Hostname The name of the server "B.a.com"
Port Port "88"
Pathname The part of the URL that is behind the host name "/index.php"
Search "?" The later part, also called the query string "? name=kang&when=2011"
Hash Returns the content after "#" "#first"
Host equals hostname + Port "B.a.com:88"
Href: The full URL of the current page "Http://www.a.com:88/index.php?name=kang&when=2011#first"

Window.location and document.location are mutually equivalent and can be exchanged for use

The 8 properties of the location are both readable and writable, but only the href and hash write make sense. For example, changing the location.href will relocate to a URL, while modifying Location.hash will jump to the anchor (<a id= "name" > or <div id= "id" > etc.) name tag (if any) in the current page ), and the page will not be reloaded

Attention
url:http://b.a.com:88/index.php?name=kang&how= #when =2011#first

Search: "? name=kang&how=" First "?" After the hash: "#when =2011#first" after the first "#" content 2, why is window.location.search empty? A : Note the difference between the search and hash above, if the url "? "Before there was a" # "for example:"http://localhost:63342/index.html#/version? " type=35&id=5"Then use Window.location.search to get Empty (" "). Because "? type=35&id=5"string character is belong to"#/version? Type=35&id=5"This string of characters, that is, query string search can only be taken to"? "After and" # "before the content, if" # "before"? " "Search value is empty. 3, Application
1 //Get URL parameters2 functiongetquerystring (name)3 {4     varafter = Window.location.hash.split ("?") [1];5     if(after)6     {7         varReg =NewRegExp ("(^|&)" + name + "= ([^&]*) (&|$)");8         varR =After.match (reg);9         if(r! =NULL)Ten         { One             returndecodeURIComponent (r[2]); A         } -         Else -         { the             return NULL; -         } -     } -}

Why is Window.location.search empty?

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.