Results 1 to 2 of 2

Thread: Help with javascript - how to open links in a new window or tab

  1. #1
    Join Date
    Aug 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with javascript - how to open links in a new window or tab

    I've found this javascript that does exactly what I was looking for. By choosing from two categories an URL is generated, that takes the user to a specific site based on what parameters the user chooses in the drop down menu. It is crucial that these links open in a new window or in a new tab - just NOT in the same tab (_self). Please help! I've posted the script below (it's working) and tried all sorts of things to make the links open in a new tab/window... no succes yet... Does anyone know what to do?

    <!DOCTYPE html>
    <html>
    <body>
    <!-- DROP-DOWN NAVIGATION MENU - III -->

    <!-- This goes in the HEAD of the html file -->

    <script language="JavaScript" type="text/javascript">
    <!-- Copyright 2001, Sandeep Gangadharan -->
    <!-- For more free scripts go to http://sivamdesign.com/scripts/ -->

    <!--

    function tothePage() { // modify the script below to match your needs
    if (document.drop.choice1.selectedIndex == 0 || document.drop.choice2.selectedIndex == 0) { return; }

    if (document.drop.choice1.selectedIndex == 1 && document.drop.choice2.selectedIndex == 1) { window.location.href="Script1.html"; }
    if (document.drop.choice1.selectedIndex == 1 && document.drop.choice2.selectedIndex == 2) { window.location.href="Script2.html"; }
    if (document.drop.choice1.selectedIndex == 1 && document.drop.choice2.selectedIndex == 3) { window.location.href="Script3.html"; }

    if (document.drop.choice1.selectedIndex == 2 && document.drop.choice2.selectedIndex == 1) { window.location.href="Program1.html"; }
    if (document.drop.choice1.selectedIndex == 2 && document.drop.choice2.selectedIndex == 2) { window.location.href="Program2.html"; }
    if (document.drop.choice1.selectedIndex == 2 && document.drop.choice2.selectedIndex == 3) { window.location.href="Program3.html"; }
    }
    // -->
    </script>

    <!-- This goes in the BODY of the html file -->

    <form name="drop">
    <select name="choice1"> // you can add as many items in this drop down list as you want
    <option selected value=0>Choose Product ...</option>
    <option value=1>Free Script</option>
    <option value=2>Free Program</option>
    </select>&nbsp;
    <select name="choice2"> // you can add as many items in this drop down list as you want
    <option selected value=0>Choose Item ...</option>
    <option value=1># 1</option>
    <option value=2># 2</option>
    <option value=3># 3</option>
    </select>
    &nbsp;<input type="button" value="Go!" onClick="tothePage()" />
    </form>


    </body>
    </html>

  2. #2
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Use window.open, as in:
    Code:
    if (document.drop.choice1.selectedIndex == 1 && document.drop.choice2.selectedIndex == 1) {window.open("Script1.html"); }
    Arie Molendijk.

Bookmarks

Posting Permissions

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