window.location

What's the difference between window.location and document.location in JavaScript?

♀尐吖头ヾ 提交于 2019-11-26 09:04:05
问题 Should both of them reference the same object? 回答1: According to the W3C, they are the same. In reality, for cross browser safety, you should use window.location rather than document.location . See: http://www.w3.org/TR/html/browsers.html#dom-location 回答2: The canonical way to get the current location object is window.location (see this MSDN page from 1996 and the W3C draft from 2006). Compare this to document.location , which originally only returned the current URL as a string (see this

Detect HTTP or HTTPS then force HTTPS in JavaScript

为君一笑 提交于 2019-11-26 06:11:37
问题 Is there any way to detect HTTP or HTTPS and then force usage of HTTPS with JavaScript? I have some codes for detecting the HTTP or HTTPS but I can\'t force it to use https: . I\'m using the window.location.protocol property to set whatever the site is to https: then refresh the page to hopefully reload a new https\'ed URL loaded into the browser. if (window.location.protocol != \"https:\") { window.location.protocol = \"https:\"; window.location.reload(); } 回答1: Try this if (location

PhoneGap for iPhone: problem loading external URL

我只是一个虾纸丫 提交于 2019-11-26 04:39:34
问题 I\'m writing an application for iPad using PhoneGap and I would like to load an external URL without triggering Safari or using internal web browser like ChildBrowser. I\'m using the PhoneGap iPad/iPhone sample project and I tried different approaches. In the onBodyLoad() function I added: window.location.href(\'http://www.wordreference.com\'); but this line opens the link using a new Safari window.From that point is not possible to come back in PhoneGap Afterwards, I tried with an AJAX

JavaScript hard refresh of current page

跟風遠走 提交于 2019-11-26 04:10:56
问题 How can I force the web browser to do a hard refresh of the page via JavaScript? Hard refresh means getting a fresh copy of the page AND refresh all the external resources (images, JavaScript, CSS, etc.). 回答1: Try to use: location.reload(true); When this method receives a true value as argument, it will cause the page to always be reloaded from the server. If it is false or not specified, the browser may reload the page from its cache. More info: The location object 回答2: window.location.href

What's the difference between window.location and document.location in JavaScript?

大兔子大兔子 提交于 2019-11-26 03:16:43
问题 Should both of them reference the same object? 回答1: According to the W3C, they are the same. In reality, for cross browser safety, you should use window.location rather than document.location . See: http://www.w3.org/TR/html/browsers.html#dom-location 回答2: The canonical way to get the current location object is window.location (see this MSDN page from 1996 and the W3C draft from 2006). Compare this to document.location , which originally only returned the current URL as a string (see this

How to remove the hash from window.location (URL) with JavaScript without page refresh?

南楼画角 提交于 2019-11-25 22:31:54
问题 I have URL like: http://example.com#something , how do I remove #something , without causing the page to refresh? I attempted the following solution: window.location.hash = \'\'; However, this doesn\'t remove the hash symbol # from the URL. 回答1: Initial question: window.location.href.substr(0, window.location.href.indexOf('#')) or window.location.href.split('#')[0] both will return the URL without the hash or anything after it. With regards to your edit: Any change to window.location will