Click here to Skip to main content
15,902,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, say im on page www.page.com
when i do window.location.href=/my var/

the result is
www.page.com/my var/

the string is appended, i dont want that, i want window.location.href to be /my var/ only

how can i do this?
your help is much appreciated :)
Posted
Comments
ZurdoDev 19-Mar-12 10:47am    
Does my var include a full url? What exactly are you trying to accomplish? A url of just a variable is invalid.

How could it work in principle?

You need to do this:
JavaScript
window.location = "http://www.CodeProject.com";


Accordingly, if you want to work with a variable, 1) it should have a valid variable name, 2) it should be assigned a value of a valid literal:

JavaScript
myLocation = "http://www.CodeProject.com";
window.location = myLocation;


—SA
 
Share this answer
 
If you put:

JavaScript
window.location.href = '/myValue'


it will append. If you say:

JavaScript
window.location.href = 'http://myValue'

it will then go to that page and not append the url.
 
Share this answer
 
Comments
Top_Coder 19-Mar-12 11:54am    
you rule! thank you so much Dominic :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900