Click on ‘heading’ and you’ll see. The structure of this seems to work for me, but somehow it doesn’t seem to work? Anyone know why? THe source code is much different from mine, and i don’t understand it much, so i decided to check my code here thanks
<script language="JavaScript">
var the_url = prompt("Which website now?", "")
var finUrl = adjust_url()
var new_window = window.open(finUrl, "opening_website")
function adjust_url() {
var checkUrl = the_url.substring(0,7)
if (checkUrl != "http://") {
the_url = "http://"+the_url
}
}
</script>
honestly I am terrible at Jav**ascript. Lost has been gone for a couple days, when he comes back I will make sure he takes a look at this He might know…
ah thanks kax, never knew you knew javascript anyways i just have a few questions
what does return the_url do??
I also wanted to make my thing exactly the same as the site i showed you (so the prompt only opens when you click a link). I copied this part from the source, but i don’t understand it. Would you mind explainin it to me?
function goThere()
{
var the_url = prompt("where can I take you?", "");
if (the_url)
{
var good_url = fixURL(the_url);
var new_window = open(good_url,"new_window","menubar,resizeable");
}
}
What i don’t get is mainly the:
if (the_url)…I don’t see any thing it is comparing to, to make the if function work.
And last question
function fixURL(the_url)
that line. Its only the beginning of a function, but what do the things in the brackets of the functions do? thankks!
I could explain it to you but your missing a part of it. There is a fixURL function that is called in that but you don’t show any reference to it in the above source. Post that and I shall explain.
ooh yah. So heres the whole thing source from the site:
<script language="JavaScript">
<!-- hide me
function goThere()
{
var the_url = prompt("where can I take you?", "");
if (the_url)
{
var good_url = fixURL(the_url);
var new_window = open(good_url,"new_window","menubar,resizeable");
}
}
function fixURL(the_url)
{
var the_first_seven = the_url.substring(0,7);
the_first_seven = the_first_seven.toLowerCase();
if (the_first_seven != 'http://')
{
the_url = "http://" + the_url;
}
return the_url;
}
// show me -->
</script>
I just need the parts i said in the above post explained. Thanks
Oh yea, there is also a line which calls the goThere() function, but i don’t think that one is important because its just a link.
What it does is take what you are typing into the prompt. In this case it would be something like http://www.google.com or just www.google.com.
This is the part that prompts you:
var the_url = prompt("where can I take you?", "");
Now this code
if (the_url)
{
var good_url = fixURL(the_url);
var new_window = open(good_url,"new_window","menubar,resizeable");
}
Where it says “if (the_url)” it is asking if the_url is true or there is something in the variable at all in this case then go inside and run the function fixURL on the_Url.
Now in fixURL, what it does is check the first 7 characters of the string to see if they are http://. If they aren’t then it adds http:// to the front of the url ( the_url = “http://” + the_url;).
Then going back up to the goThere() function it pops open a new window using your “fixed” url.
That should explain it but post any questions you have blah.
:p: