window.location

Does Android support window.location.replace or any equivalent?

风格不统一 提交于 2019-11-26 21:46:58
问题 It seems that the Android browser doesn't properly implement window.location.replace . In most browsers, calling window.location.replace will replace the current URL with the URL passed to it. When the user navigates somewhere else then clicks back, they'll be returned to the URL that was passed to window.location.replace , rather than the URL that they were at before window.location.replace was called. The Android browser doesn't seem to implement this properly. In the Android browser, the

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

旧巷老猫 提交于 2019-11-26 20:57:44
Should both of them reference the same object? rahul 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 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 page on MSDN ). Probably to avoid confusion, document.location was replaced with document.URL (see here on

Change hash without reload in jQuery

巧了我就是萌 提交于 2019-11-26 19:17:12
问题 I have the following code: $('ul.questions li a').click(function(event) { $('.tab').hide(); $($(this).attr('href')).fadeIn('slow'); event.preventDefault(); window.location.hash = $(this).attr('href'); }); This simply fades a div in based on when you click but I want the page URL hash tag to change when you click so people can copy and bookmark it. At the moment this effectively reloads the page when the hash tag is change. Is it possible to change the hash tag and not reload the page to

Detect HTTP or HTTPS then force HTTPS in JavaScript

独自空忆成欢 提交于 2019-11-26 18:09:31
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(); } Soumya Try this if (location.protocol != 'https:') { location.href = 'https:' + window.location.href.substring(window.location.protocol.length);

Is there a way to have an onload callback after changing window.location.href?

≡放荡痞女 提交于 2019-11-26 16:52:14
问题 Essentially what I'd like to do is something to the effect of this: window.location.href = "some_location"; window.onload = function() { alert("I'm the new location and I'm loaded!"); }; Is there any way to have a callback when the window's new location is loaded? (The above code doesn't work.) 回答1: No, you cannot do it the way you want. Loading a new page closes the current document and starts loading a new document. Any code in your current document will no longer be active when the new

What happens to code after a javascript redirect (setting window.location.href)?

谁说我不能喝 提交于 2019-11-26 16:40:02
问题 I have the following javascript redirect code followed by some more code. window.location.href = '/someurl'; alert('hello'); alert('hello again'); This causes a browser inconsistency. In firefox, the first alert is visible for a split second right before getting redirected. The second alert is not visible at all. In chrome, both alerts will pop up, and the redirect happens only after clicking ok for both alerts. Is there some concept of what happens to code after the redirect that can resolve

PhoneGap for iPhone: problem loading external URL

二次信任 提交于 2019-11-26 15:56:21
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 request substituting the content of the page using document.write function loadHTML(url, timeout) { if (timeout

JavaScript hard refresh of current page

橙三吉。 提交于 2019-11-26 15:07:39
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.). CMS 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 window.location.href = window.location.href 来源: https://stackoverflow.com/questions/2099201/javascript-hard-refresh-of-current

Adding http headers to window.location.href in Angular app

最后都变了- 提交于 2019-11-26 14:12:24
问题 I have a angular app that I needed to redirect outside to a non angular html page, so I thought I could just use the $window.location.href to redirect the angular app to my external site. This actually works fine, however, I have a nodejs/express backend that checks for auth token before serving up any content(even static content). This requires a auth token to be sent in the header of the http request. Now the question: Can/How do you add an auth token to the request that is made by changing

Difference between window.location.assign() and window.location.replace()

二次信任 提交于 2019-11-26 10:25:00
问题 What is the difference between window.location.assign() and window.location.replace() , when both redirect to a new page? 回答1: Using window.location.assign("url") will just cause a new document to load. Using window.location.replace("url") will replace the current document and replace the current History with that URL making it so you can't go back to the previous document loaded. Reference: http://www.exforsys.com/tutorials/javascript/javascript-location-object.html 回答2: The difference is