Page 1 of 1
Not redirecting
Posted: Fri Oct 24, 2003 8:17 am
by Nay
Hey, I was thinking, I'm going to have this page saved in my hard drive and have it as a link in the Links bar. Well, it's supposed to prompt me and It'll redirect me to the page I want, at PHP.net. Here it goes:
Code: Select all
<script language="JavaScript">
<!--
var location = prompt("Which function?", "Enter here");
var new_location = "http://php.net/" + location;
window.location = new_location;
//-->
</script>
Well, I get the prompt but after that, it doesn't go anywhere. Any ideas?
-Nay
Posted: Fri Oct 24, 2003 8:49 am
by JayBird
use document.location
not
window.location
Mark
Posted: Fri Oct 24, 2003 8:51 am
by JayBird
it might be better to do it this way
Code: Select all
<script language="JavaScript">
<!--
var location = prompt("Which function?", "Enter here");
if(location) {
document.location = "http://php.net/" + location;
}
//-->
</script>
because, the way you did it, the user will still be redirected if the click cancel. This way, you can put an else statement in a do something if the click cancel.
Mark
Posted: Fri Oct 24, 2003 8:52 am
by Nay
woohoo thanks Bech. Now it's working:
Code: Select all
<script language="JavaScript">
<!--
var location = prompt("Which function?", "Enter here");
var new_location = "http://php.net/" + location;
if(new_location=="null") {
document.location = "http://php.net/";
} else {
document.location = new_location;
}
//-->
</script>
So I don't have to manually type anymore

.
-Nay
edit: I don't know about anyone, but I'd like to be redirected to php.net if I did not enter a function. So I can have a 2-in-1 kind of a link.
Posted: Fri Oct 24, 2003 9:02 am
by JayBird
The way you have done it isn't wrong, but i think this would be more correct in the code world.
Code: Select all
<script language="JavaScript">
<!--
var location = prompt("Which function?", "Enter here");
var new_location = "http://php.net/" + location;
if(new_location) {
document.location = new_location;
} else {
document.location = "http://php.net/";
}
//-->
</script>
Posted: Fri Oct 24, 2003 9:06 am
by Nay
hehe, yeah, thanks. I'm not much into Javascript. I was wondering if there was an isSet() for Javascript, then I couldn't find any so I did it that way lol.
-Nay
Posted: Fri Oct 24, 2003 9:12 am
by JayBird
this works, cos if you press cancell NULL is retured the the if is false.
Posted: Fri Oct 24, 2003 9:14 am
by JayBird
you could aslo just add this link to your favourites which will do the same thing
Code: Select all
javascript:q=document.selection.createRange().text;if(!q)void(q=prompt('PHP%20Reference:',''));if(q)location.href='http://se.php.net/manual-lookup.php?function='+escape(q)
Works a treat
Mark
Posted: Fri Oct 24, 2003 9:33 am
by Nay
Okay, nevermind it all now. I got fustrated with JavaScript since I still get redirected to "
http://www.php.net/null". So I did this:
locahost/phpnet/index.html:
Code: Select all
<script language="JavaScript">
<!--
var location = prompt("Which function?", "Enter here");
var new_location = "parse.php?function=" + location;
document.location = new_location;
//-->
</script>
localhost/phpnet/parse.php:
Code: Select all
<?php
$function = $_GET['function'];
if(isSet($function) && $function != "null") {
$location = "http://www.php.net/" . $function;
header("Location: $location");
} else {
header("Location: http://www.php.net/");
}
?>
There! I love it better now, since there's some PHP in it

.
-Nay