window.location is a property in JavaScript for getting the current page's location.
Questions tagged [window.location]
618 questions
431
votes
6 answers
JavaScript: location.href to open in new window/tab?
I have a JavaScript file from a third party developer. It has a has link which replaces the current page with the target. I want to have this page opened in a new tab.
This is what I have so far:
if (command == 'lightbox') {
…
![](../../users/profiles/299871.webp)
iamjonesy
- 23,004
- 39
- 130
- 203
364
votes
17 answers
How to remove the hash from window.location (URL) with JavaScript without page refresh?
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.
![](../../users/profiles/25068.webp)
Tom Lehman
- 75,197
- 69
- 188
- 262
336
votes
13 answers
Detect HTTP or HTTPS then force HTTPS in JavaScript
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…
![](../../users/profiles/388473.webp)
Registered User
- 7,674
- 8
- 28
- 39
272
votes
16 answers
What's the difference between window.location and document.location in JavaScript?
Should both of them reference the same object?
![](../../users/profiles/26349.webp)
Morgan Cheng
- 66,562
- 63
- 166
- 223
203
votes
3 answers
JavaScript hard refresh of current page
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.).
![](../../users/profiles/212700.webp)
leepowers
- 35,484
- 22
- 93
- 127
109
votes
4 answers
Difference between window.location.assign() and window.location.replace()
What is the difference between window.location.assign() and window.location.replace(), when both redirect to a new page?
![](../../users/profiles/179669.webp)
Bakudan
- 17,636
- 9
- 48
- 69
83
votes
9 answers
window.location versus just location
Across the web, I see a vast number of JavaScript programmers writing window.location instead of just location. I was curious if anyone could offer an explanation as to why. window is the global object, and therefore it is unnecessary to include --…
![](../../users/profiles/236139.webp)
Reid
- 16,827
- 5
- 35
- 35
59
votes
3 answers
How can I make a HTML a href hyperlink open a new window?
This is my code:
test
When you click it, it takes you to Yahoo but it does not open a new window?
![](../../users/profiles/596952.webp)
TheBlackBenzKid
- 24,177
- 36
- 128
- 199
55
votes
5 answers
Change hash without reload in jQuery
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…
![](../../users/profiles/235889.webp)
daveredfern
- 1,185
- 4
- 13
- 15
51
votes
6 answers
What is the difference between "window.location.href" and "window.location.hash"?
I learned "window.location.hash" new and tried in my jquery code instead of "window.location.href" and both of them gave same results.
Code is here :
window.location.href = ($(e.currentTarget).attr("href"));
window.location.hash =…
![](../../users/profiles/1348435.webp)
kalaba2003
- 1,171
- 2
- 19
- 31
43
votes
3 answers
Setting JavaScript window.location
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,…
![](../../users/profiles/439687.webp)
Mark
- 655
- 2
- 7
- 9
35
votes
1 answer
possible to replace window.location.hash?
I'm wondering whether it's possible to change the hash in window.location.hash and replace it with 'this.id'. Or would I need to change the entire window.location?
![](../../users/profiles/355010.webp)
circey
- 1,972
- 6
- 33
- 50
34
votes
3 answers
removing the # from window.location.hash
I have this simple script:
$(document).ready(function(){
var $yoyo = window.location.hash;
alert($yoyo);
});
But I need to get rid of the # symbol as I'll be using the variable to locate div ids. I've tried using .remove('#') but that doesn't…
![](../../users/profiles/355010.webp)
circey
- 1,972
- 6
- 33
- 50
31
votes
2 answers
What happens to code after a javascript redirect (setting window.location.href)?
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…
![](../../users/profiles/1385729.webp)
user1385729
- 1,136
- 14
- 19
30
votes
3 answers
Clearing URL hash
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…
![](../../users/profiles/707381.webp)
Randomblue
- 98,379
- 133
- 328
- 526