0

I Have the following code i am trying to redirect the page to the same page but with a int on the link but it keeps coming up with page error.

 var done_update = '&updated=1';
 window.location = window.location.href.done_update;

Thank you,

3 Answers 3

2

String concatenation is done in JavaScript (and Java for that matter) using a + and not a .:

var done_update = '&updated=1';
window.location = window.location.href + done_update;
0
2
var done_update = '&updated=1';
window.location = window.location.href+done_update;
1
var done_update = "&update=1";
location = location.href + done_update;
  1. String concatenation in JavaScript is done using the + operator, not . as in other languages (Perl, PHP...)

  2. location is a global variable, there is no need to specify window.location

2
  • 2
    I would say 2 is a personal preference. I almost always use an explicit reference to window objects and properties, there's no risk of overriding them in local scopes that way.
    – Andy E
    Sep 4, 2010 at 12:27
  • 1
    If you put it that way it is reasonable to use window.location. However all global variables are properties of window, do you also use window.document?
    – ase
    Sep 4, 2010 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.