www.webdeveloper.com
Results 1 to 3 of 3

Thread: Creating a psuedo browser

  1. #1
    Join Date
    Nov 2002
    Posts
    3

    Creating a psuedo browser

    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.
    Code:
    <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>

  2. #2
    Join Date
    Nov 2002
    Posts
    631
    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.

  3. #3
    Join Date
    Nov 2002
    Location
    Mexico City
    Posts
    52
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles