Does anyone know what's the problem with this javascript code here:
function a() {
var origionalurl = window.location
var arraywithurl = origionalurl[1].split("=")
var finalurl = arraywithurl[1]
alert(finalurl)
window.location = finalurl
}
I'm a begginer, so it's probably something very basic.
What I'm trying to do is redirect someone to a URL in a variable called "loc" in the address bar. So, I get the starting URL (It would look something like "myURL?loc=another_URL") and split it into two parts ("myURL?loc" and "another_URL") and then tell the person a message and then redirect them to "another_URL". What's my problem?
Last edited by shane.carr; 05-31-2006 at 06:36 PM.
Reason: changed "java" to "javascript"
Does anyone know what's the problem with this java code here:
function a() {
var origionalurl = window.location
var arraywithurl = origionalurl[1].split("=")
var finalurl = arraywithurl[1]
alert(finalurl)
window.location = finalurl
}
That isn't java code. That is JavaScript code. Java is something totally and separately different from JavaScript and, thus, the two should not be confused with one another.
Otherwise... Besides the correction given in the previous post, this:
var origionalurl = window.location
should be this:
var origionalurl = window.location.search.substr(1);
Thanks both of you! Some of it is fixed, but, the redirecting part still doesn't work. I do get a message with another_URL , but I'm not redirected to it. It redirects me to myURL with no get variables (see first post).
Here is the code I have now:
Code:
function a() {
var origionalurl = window.location.search.substr(1);
var arraywithurl = origionalurl.split("=");
var finalurl = arraywithurl[1];
alert(finalurl);
window.location = finalurl;
}
even if I put in something like "document.loaction.href = "http://www.google.com/" it still doesn't work! It redirects me to the just original (myURL) page!
Bookmarks