Questions tagged [window.location]

window.location is a property in JavaScript for getting the current page's location.

671 questions
32
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…
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…
Randomblue
  • 112,777
  • 145
  • 353
  • 547
28
votes
3 answers

Is it secure to use window.location.href directly without validation

Is it secure to use window.location.href without any validation? For example: From the above example, is it vulnerable to Cross-site scripting (XSS) attack? If it is, then…
overshadow
  • 958
  • 2
  • 15
  • 31
26
votes
5 answers

PhoneGap for iPhone: problem loading external URL

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…
Claus
  • 5,662
  • 10
  • 77
  • 118
26
votes
3 answers

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

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…
Lukas
  • 9,765
  • 2
  • 37
  • 45
25
votes
1 answer

What's the difference between $locationChangeSuccess and $locationChangeStart?

What's the difference between $locationChangeSuccess and $locationChangeStart? They are both undocumented events related to window.location.
Lior
  • 40,466
  • 12
  • 38
  • 40
23
votes
12 answers

window.location.search query as JSON

Is there a better way to convert a URL's location.search as an object? Maybe just more efficient or trimmed down? I'm using jQuery, but pure JS can work too. var query = window.location.search.substring(1), queryPairs = query.split('&'), queryJSON =…
thugsb
  • 22,856
  • 6
  • 30
  • 44
23
votes
2 answers

Capture incoming URL Parameters, then pass to iFrame Src with Javascript

So trying to figure out how to do this with window.location in Javascript. I'm sending users to our site with an appended URL with a Google Analytics code that I need to pass to an iframe src on that page. I'd assume Javascript could do this (note -…
22
votes
1 answer

Is JavaScript location.href call asynchronous?

function fun(){ console.log("Hi"); window.location.href="http://www.google.com"; console.log("Hello, how are you"); alert("I am good"); fun1(); } function fun1(){ console.log("Whats up??"); } In the above lines of code the…
shreyansh
  • 1,637
  • 4
  • 26
  • 46
22
votes
1 answer

Javascript: How to catch error on page navigated to using window.location.href = url

I am using a REST service to generate a CSV file that I want to prompt the user to download. An example of the service is below: https://localhost:8444/websvc/exportCSV?viewId=93282392 To prompt the user to download the file, I use this…
Matt
  • 23,363
  • 39
  • 111
  • 152
21
votes
2 answers

Reload a page with location.href or window.location.reload(true)

I need to reload a page in a success of an ajax call. I'm seeing some code (not mine) and there are two ways: success: function(obj) { //code location.href = location.href; } or success: function(obj) { //code …
pmiranda
  • 7,602
  • 14
  • 72
  • 155
21
votes
3 answers

What exactly can an IFrame do with the top.Location object (cross-domain)?

There is a very particular edge case in cross-domain policies regarding the window.top.Location object... Let's say I have IFrame A , in domain www.bbb.com, living inside a page in domain www.aaa.com. The page inside the IFrame can: Compare…
Daniel Magliola
  • 30,898
  • 61
  • 164
  • 243
20
votes
5 answers

Mock window.location.reload in Jasmine testing

I have created a window.location.reload function in my javascript. I need to mock the reload function while testing in Jasmine since it keeps on looping. The test goes well when I run grunt jenkins. But not while testing in the browser…
Viji Pandithurai
  • 349
  • 1
  • 2
  • 6
19
votes
2 answers

Reload page when changing hash

Reload page when changing hash. I have a simple one-page site with several 'pages' on it. These pages are in one wide container which scrolls when you choose one. I have added a hash to the URL so that you can locate to specific pages directly. This…
andyfurniss
  • 283
  • 1
  • 3
  • 12
17
votes
4 answers

window.location.href not working

My website is http://www.collegeanswerz.com/. I'm using rails. The code is for searching for colleges. I want the user to be able to type in the colleges name, click enter, and be taken to the url, rather than seeing the search results (if the…
Adam Zerner
  • 17,797
  • 15
  • 90
  • 156
1
2
3
44 45