window.location

Clearing URL hash

[亡魂溺海] 提交于 2019-11-28 19:12:00
Visit stackoverflow.com/#_=_ and window.location.hash evaluates to #_=_ . Fine. Now execute window.location.hash = '' to clear the hash, and the URL becomes stackoverflow.com/# . (Notice the trailing # .) Why is the # in window.location.hash inconsistently included or excluded? How can the # be removed from the URL without reloading the page? ( MDN says [the hash is] the part of the URL that follows the # symbol, including the # symbol. but that is not true for in the case of an empty hash.) To answer the second question (removing the # without a page refresh): history.pushState('', document

How can I make a HTML a href hyperlink open a new window using window.location?

我的未来我决定 提交于 2019-11-28 18:07:50
This is my code: <a href="http://www.google.com" onClick="window.location.href='http://www.yahoo.com';return false;" target="_blank">test</a> When you click it, it takes you to Yahoo but it does not open a new window? John <a href="#" onClick="window.open('http://www.yahoo.com', '_blank')">test</a> Easy as that. Or without JS <a href="http://yahoo.com" target="_blank">test</a> 来源: https://stackoverflow.com/questions/13335954/how-can-i-make-a-html-a-href-hyperlink-open-a-new-window-using-window-location

Is there any difference with using only location vs using window.location across browsers

↘锁芯ラ 提交于 2019-11-28 11:31:37
I find myself always writing: console.log(window.location.href); without even thinking about it. The majority of answers on SO also write it this way. Is there any reason why I can't just write: location.href since location is an object at window level? Are there any cross-browser compatibility issues with this? To Clarify: I know there is document.location - that is NOT what this question is about. This is about if there is any difference with using only location vs using window.location across browsers. There are some differences. In global scope, there is absolutely no difference between

window.location = #anchor doesn't work in IE

岁酱吖の 提交于 2019-11-28 10:33:49
On this map: http://web.pacific.edu/documents/marketing/campus-map/version%202/stockton-campus-2.0.htm I have an anchor at the top, and I want the page to jump to the anchor when a link is clicked. I'm currently using window.location = '#top'; It works as expected in FF, Opera, and Chrome, but not in IE 7. I've tried all permutations like window.location.hash and window.location.assign() and also scrollIntoView(true) and focus(). How can I make it work in IE? Edit : Nothing seems to work, which makes me think it's not the syntax, but something about the JS... here is the click event handler...

Setting JavaScript window.location

社会主义新天地 提交于 2019-11-28 04:29:44
I'm currently setting the window.location.pathname property to redirect the user to a relative URL. The new URL has parameters, so the line of JavaScript looks like this: window.location.pathname = window.location.pathname.substring( 0, window.location.pathname.lastIndexOf( '/' ) + 1 ) + 'myPage.xhtml?u=' + selected_user.Username; This is successful in Firefox, however Chrome encodes the question mark with '%3F' and the request subsequently fails. I'm not sure if I'm using window.location properly. Do I need to use properties of window.location such as pathname or href? I've found that as soon

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

假如想象 提交于 2019-11-28 00:32:51
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 user will be directed back to the original URL rather than the one passed to window.location.replace .

Triggering shouldStartLoadWithRequest with multiple window.location.href calls

狂风中的少年 提交于 2019-11-27 19:11:35
Im trying to pass multiple things from a webpage inside a UIWebView back to my iPhone app via the shouldStartLoadWithRequest method of the UIWebView. Basically my webpage calls window.location.href = "command://foo=bar" and i am able to intercept that in my app no problem. Now if i create a loop and do multiple window.location.href calls at once, then shouldStartLoadWithRequest only appears to get called on once and the call it gets is the very last firing of window.location.href at the end of the loop. The same thing happens with the webview for Android, only the last window.location.href

Change hash without reload in jQuery

徘徊边缘 提交于 2019-11-27 18:06:21
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 prevent the jumping effect? This works for me $('ul.questions li a').click(function(event) { event

Create a link that either launches iOS app, or redirects to app store [duplicate]

浪子不回头ぞ 提交于 2019-11-27 18:04:22
问题 Possible Duplicate: Is it possible to register a http+domain-based URL Scheme for iPhone apps, like YouTube and Maps? I have a custom URL scheme for my iOS app, and I want to be able to email a link to someone that will either launch the app if it's on the device, or take them to the app store if they don't have it. I'd like to be able to send myapp://someurl and have that either launch or go to myapp on the appstore, but I don't think this will work out of the box. Instead, I'm thinking of

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

非 Y 不嫁゛ 提交于 2019-11-27 14:38:00
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.) 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 page starts to load. To have an event handler when the new document loads, you would either need to insert code