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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    New Browser Window

    Hi,

    Although I get by with coding for what I need on my web pages, and spend enormous amounts of hours doing so, I am now asking for some help.

    I wish to call for a new window in a browser when clicking on the option value in the code below. This drop and go link list box works fine and it calls for the web page, but I need a new browser window to come up after clicking.

    I tried 100, and I mean 100 things, and searched for tutorials but no luck.

    Here's the code;

    <select name="DropGoCombo0" onChange="GoNow0(this.form)" size=1>
    <option value=http://pcchill.com/xcart/catalog/Seal-String-p-35.html>Seal String
    <option value="4.html">test
    <option value="5.html">test
    <option value="" selected>(VIEW & ADD COOLING ACCESSORIES TO CART)
    </select>



    </BODY>
    <script language="JavaScript">
    <!--
    function GoNow0(Form){
    var i=Form.DropGoCombo0.selectedIndex;
    var g=Form.DropGoCombo0.options[i].value;
    if (g!="") parent.location=g;
    }
    //------>

    </script>

    </HTML>



    Any help would be very much appreciated.

    Last edited by Whizzz; 01-19-2006 at 01:22 AM.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,964
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Code:
    <select name="DropGoCombo0" onChange="GoNow0(this)" size=1>
    <option value=http://pcchill.com/xcart/catalog/Seal-String-p-35.html>Seal String
    <option value="4.html">test
    <option value="5.html">test
    <option value="" selected>(VIEW & ADD COOLING ACCESSORIES TO CART)
    </select>
    ...
    function GoNow0(oSel){
      var i = oSel.selectedIndex;
      var g = oSel.options[i].value;
      if (g!="") window.open(g, "_blank");
    }
    That will always open a new window even if a page is already open. If you want to open each file in its own new window, use this:
    Code:
    function GoNow0(oSel){
      var i = oSel.selectedIndex;
      var g = oSel.options[i].value;
      if (g!="") {
         var w = window.open(g, "popup"+i);
         w.focus();
      }
    }

  • #3
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by glenngv
    Code:
    window.open(g, "_blank");
    Interesting.
    Tbh, maybe I've lead a sheltered life, but that's the first time I've seen markup target values used as an argument within the window.open method.
    I had to quickly test it out for myself, just to be sure.

    I would have expected js to treat a markup value - namely _blank - like a custom string literal (and reuse it), rather than 'understand' it and use it accordingly.

    It's unlikely to make me start loving popups, but it's useful to know. So, ta.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,964
    Thanks
    0
    Thanked 236 Times in 233 Posts
    "_blank" in window.open method is treated by javascript as any other string literal. But it also understands that markup target values such as "_blank", "_self", "_top", "_parent" or any user-defined values function the same way in window.open.

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,465
    Thanks
    0
    Thanked 633 Times in 623 Posts
    You can also set the fourth parameter of your window.open call to true or false to control whether to reuse an existing window or not.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,964
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Can you point me to a reference that says window.open has 4th parameter?
    The way to reuse existing popup window is by using the same user-defined target name.
    Code:
    window.open(url1, "popup");
    window.open(url2, "popup");
    Both url1 and url2 will open in the same popup window named "popup".


  •  

    Posting Permissions

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