Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

making a hyperlink using javascript

Status
Not open for further replies.

estesflyer

Programmer
Dec 19, 2000
284
US
how do you make a hyperlink using javascript?
 
actually, waht im trying to say, is how do you get a browser window to open a webpage submitted by a command prompt. like, the user types in where he wants to go, and clicks ok, then he's off! im trying to get the url to open in the current browser.
 
<script>

t=prompt(&quot;Please enter a url.&quot;)
window.location=t

</script> jared@aauser.com
 
for some reason or another, the URL entered wont work. it always goes to a page that says, the page you have requested cannot be found.
<script language=&quot;javascript&quot; type=&quot;text/javascript&quot;>
<!--
window.alert(&quot;what do you want to do today, surf the web, or do you want to play a game?&quot;);
var command=window.prompt(&quot;type surf_web, or game_plz in the field below.&quot;);
if (command == &quot;surf_web&quot;) {
var url=window.prompt(&quot;what website do you want to go to?&quot;,&quot;type URL here&quot;);
window.alert(&quot;bye!&quot;);
window.location = url;
}
else if (command == &quot;game_plz&quot;) {
window.alert(&quot;ok, we can play a game!&quot;);
window.alert(&quot;its not a very fun game, but its the thought that counts right? right??&quot;);
var friend=window.prompt(&quot;give me one of your friend's names plz.&quot;,&quot;type name here&quot;);
var enemy=window.prompt(&quot;now give me a name of one of your enemies(if you have any).&quot;,&quot;type name here&quot;);
var gender=window.prompt(&quot;Is your enemy a male or a female?&quot;,&quot;type male or female plz.&quot;);
if (gender == &quot;male&quot;) {
var gender=&quot;him&quot;;
}
else if (gender == &quot;female&quot;) {
var gender=&quot;her&quot;;
}
var string=&quot;&quot; + friend + &quot; and a monkey ran over to &quot; + enemy + &quot;, and laughed at &quot; + gender;
window.alert(string);
window.alert(&quot;that was fun wasn't it! wasn't it?&quot;);
window.alert(&quot;Ok, Since your board of me already, I guess we can just talk later, dat ok? good! ^_^&quot;);
}
//-->
</script>
 
you may want to make sure that the text http:// is included

function jumpTo()
{
t=prompt(&quot;Please enter a url.&quot;,'')
if(t==null){return false}
if(t.indexOf(&quot; window.location=t
}
jumpTo()

you could do a lot more validation on the url, but this should help jared@aauser.com
 
next to each &quot;htt..&quot; string is a semicolon - the emsage board inserted them, so take them out if you want your script to work jared@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top