Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get URL to open in new window

    So basically what I am trying to do is have a form that acts like an address bar, for example if someone was to enter the text into the form field like Google it will open the website in a new window.

    here is what i have so far.

    Javascript
    Code:
    <script type="text/javascript">
    <!--
    function gotoURL() {
    var newURL = document.url2go.go.value
    document.location.href=newURL
    }
    //-->
    </script>

    HTML CODE:
    Code:
    <form action="javaScript:gotoURL()" method="get" name="url2go" >
    <input type="text" name="go" value="http://" size="100">
    <input type="submit" value="Go">
    </form>
    I can get it to open the website in the current window but I cannot get it to open the website in a new window. When I put the
    Code:
    traget="_new"
    into the form it will open a new tab but it goes to about:blank and not the site. Any help would be greatly appreciated

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,314
    Thanks
    203
    Thanked 2,565 Times in 2,543 Posts
    Which of the three places (new window, new tab, same tab) web pages open is completely under the browser's owner's control. You can only suggest where it should open in your code and the browser can be set to ignore your suggestion and open it where the browser owner wants it to open.

    Your visitor is supposed to be the one deciding what opens where - that's why the target attribute was made obsolete in 1997. It was only valid in HTML 3.2.
    Most people don't want new browser windows opening any more and prefer either to have them open in a new tab or as an overlay on the current page. There never has been any way to specify a new tab in HTML or JavaScript since tabbed browsers were introduced long after 1997.

    Quizmaster: The Jungfrau is a well-known peak in which country?
    Contestant: China

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Mar 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok so what i am doing is designing a site that is accessed through Chrome Kiosk mode. which opens in a full window and the only way to close it is through keyboard shortcuts , i have disabled all closing shortcut keys except alt+w on the computer system. I want the URL to open in a new tab so that the original (for lack of a better term) portal page(which is local only) does not close. I have a script that will automatically logout of the system and restart the front page when i want it to. so all i need now is to get the dang urls to open in a new window.

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,020
    Thanks
    56
    Thanked 566 Times in 563 Posts
    the "standard" way of opening a new window is wit the window.open() method. Although as Philip says, you can't control where it opens and pop up blockers may stop it from opening at all. Setting the window's dimensions to the same as the screen's seems to work OK in my version of Chrome...

    Code:
    <body>
    <form name="url2go" >
    <input type="text" name="go" value="http://" size="100">
    <input type="button" value="Go" onclick="gotoURL(this.form)">
    </form>
    <script type="text/javascript">
    <!--
    function gotoURL(frm) {
    var ht=screen.height;
    var wd=screen.width;
    window.open(frm.go.value,"","height="+ht+", width="+wd); 
    }
    //-->
    </script>
     </body>
    Last edited by xelawho; 03-25-2014 at 08:21 PM.


  •  

    Posting Permissions

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