Click to See Complete Forum and Search --> : Creating a psuedo browser


Clouded-Ice
11-27-2002, 03:18 PM
I'm trying to create a little psuedo browser. I have the visitor type in the website into a text box then they click "Go." By clicking on "Go" they activate the url() function, but I seem to get an error written the way I have it.

<script language="JavaScript">
<!--
function url() {
browser.document.location = frm.url.value
}
//-->
</script>

<form name="frm">
<input type="text" name="url" size="75">
<input type="button" value="Go" name="Go" onClick="url()">
<br><iframe name="browser" height="89.5%" width="100%">
Your browser does not support inline frames or is currently
configured not to display inline frames.
</iframe></form>

Zach Elfers
11-29-2002, 08:50 PM
Why don't you do it this way?

<form>
<input type="text" name="URL">
<script language="JavaScript" type="text/JavaScript">

document.write("<a href=\"" + form.URL.value + "\" target=\"browser\">GO<\/a>");

</script>
</form>

That should do what you want it to.

Paco Zarabozo
11-30-2002, 03:56 AM
Or, more simple, just correct your url function to this:

function url() {
parent.browser.location.href = document.frm.url.value
}

You'll need a function to check if your user has typed "http://" or not, because location.href="www.yahoo.com" won't send him to yahoo.com, but http://yourserver.com/www.yahoo.com. That would be this:

function url() {
d = document.frm;
if (d.url.value.substring(0,7) != 'http://') {
v = d.url.value;
if ((v.indexOf('.com') != -1) || (v.indexOf('.net') != -1) || (v.indexOf('.org') != -1) || (v.indexOf('.ws') != -1) || && (v.indexOf('.biz') != -1) || (v.indexOf('.name') != -1) || (v.indexOf('.co') != -1) || (v.indexOf('.info') != -1)) {
d.url.value = 'http://'+v;
}
}
parent.browser.location.href = frm.url.value;
}


It's difficult to validate a domain, so i hope to cover most common possibilities with that code.

Paco.