{"id":236,"date":"2021-03-21T15:22:48","date_gmt":"2021-03-21T15:22:48","guid":{"rendered":"https:\/\/wshop.fi\/eng\/?p=236"},"modified":"2021-03-21T15:22:49","modified_gmt":"2021-03-21T15:22:49","slug":"javascript-window-location-object-properties","status":"publish","type":"post","link":"https:\/\/wshop.fi\/eng\/javascript-window-location-object-properties\/","title":{"rendered":"Javascript Window Location object Properties"},"content":{"rendered":"\n<p><strong>Javascript window location object properties contain information about the current URL<\/strong>.&nbsp;For example\u201d location.pathname\u201d returns \u201c\/subdirectory\/search.\u201d<\/p>\n\n\n\n<p>Example URL: http:\/\/www.domain.com\/subdirectory\/search?filter=a#somewhere<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Javascript Window Location Object Properties<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th><strong>Property<\/strong><\/th><th><strong>Description<\/strong><\/th><th><strong>Returns<\/strong><\/th><\/tr><tr><td>hash<\/td><td>Returns the anchor portion of a URL<\/td><td>#somewhere<\/td><\/tr><tr><td>host<\/td><td>Returns the hostname and port of a URL<\/td><td>www.domain.com (will include port if one exists)<\/td><\/tr><tr><td>hostname<\/td><td>Returns the hostname of a URL<\/td><td>www.domain.com<\/td><\/tr><tr><td>href<\/td><td>Returns the entire URL<\/td><td>http:\/\/www.domain.com\/subdirectory\/search?filter=a#somewhere<\/td><\/tr><tr><td>pathname<\/td><td>Returns the path name of a URL<\/td><td>\/subdirectory\/search<\/td><\/tr><tr><td>port<\/td><td>Returns the port number the server uses for a URL<\/td><td>(empty string)<\/td><\/tr><tr><td>protocol<\/td><td>Returns the protocol of a URL<\/td><td>http:<\/td><\/tr><tr><td>search<\/td><td>Returns the query portion of a URL<\/td><td>?filter=a<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Javascript Window Location Object Properties Alert<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>   &lt;script type=\"text\/javascript\">\n        \/\/note some parts may be blank depending on your URL\n        alert(\"hash: \" + location.hash + \"\\n\" +\n        \"host: \" + location.host + \"\\n\" +\n        \"hostname: \" + location.hostname + \"\\n\" +\n        \"href: \" + location.href + \"\\n\" +\n        \"pathname: \" + location.pathname + \"\\n\" +\n        \"port: \" + location.port + \"\\n\" +\n        \"protocol: \" + location.protocol + \"\\n\" +\n        \"search: \" + location.search );  \n    &lt;\/script><\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Javascript window location object properties contain information about the current URL.&nbsp;For example\u201d location.pathname\u201d returns \u201c\/subdirectory\/search.\u201d Example URL: http:\/\/www.domain.com\/subdirectory\/search?filter=a#somewhere Javascript Window Location Object Properties Property Description Returns hash Returns the anchor portion of a URL #somewhere host Returns the hostname and port of a URL www.domain.com (will include port if one exists) hostname Returns the hostname [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":178,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":{"0":"post-236","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-coding"},"_links":{"self":[{"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/posts\/236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/comments?post=236"}],"version-history":[{"count":1,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/posts\/236\/revisions"}],"predecessor-version":[{"id":237,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/posts\/236\/revisions\/237"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/media\/178"}],"wp:attachment":[{"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/media?parent=236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/categories?post=236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/tags?post=236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}