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 10 of 10
  1. #1
    jfm
    jfm is offline
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to cause link to open in new window

    Here's a snippet of code provided by automotive.com to put local gas prices on a web site. Problem is, the link opens in the same window. I want it to open a new window. I would appreciate it if someone could tell me how to change the code to do this.

    Here's the code:

    Code:
    <div><style type="text/css">
    .AutomotiveLink { COLOR: #df0005; TEXT-DECORATION: none } 
    .City { font-family:arial narrow, san-serif;font-size:12px;font-weight:bold; } 
    .CitySub { font-family:arial, san-serif;font-size:10px } 
    .inZip { Font-Family:arial,san-serif;FONT-SIZE:10px;HEIGHT:19px;vertical-align:middle; } </style>
    <table width="120" height="125" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td background="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/REGIONAL_GAS_WIDGET-125X125.gif" height="31" align="center">
    <table border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td id="spCity" align="center" height="16" class="City">
    </td>
    </tr>
    <tr>
    <td align="center" height="14" class="CitySub">Average Gas Price</td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td height="35" background="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/REGIONAL_GAS_WIDGET-125X-02.gif" align="center"><span id="spPrice" style="FONT-SIZE:20px; COLOR:white; FONT-FAMILY:'arial black', san-serif"></span><span style="FONT-SIZE:10px; COLOR:white; FONT-FAMILY:'arial narrow',san-serif">Per Gallon</span>
    </td>
    </tr>
    <tr><td background="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/REGIONAL_GAS_WIDGET-125X-03.gif" height="17">
    </td>
    </tr>
    <tr><td height="23" background="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/REGIONAL_GAS_WIDGET-125X-04.gif" align="center"><input type="text" id="inZipRegionalLarge" size="9" class="inZip" value="Enter Zip" onclick="clearTextBox('inZipRegionalLarge');">&nbsp;&nbsp;<img src="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/GO.gif" height="13" style="vertical-align:middle;" onclick="automotiveRedirect('inZipRegionalLarge');" >
    </td>
    </tr>
    <tr><td height="19" background="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/REGIONAL_GAS_WIDGET-125X-05.gif" style="PADDING-RIGHT:3px;PADDING-LEFT:3px" align="center"><span style="FONT-SIZE:10px; FONT-FAMILY:'arial narrow',san-serif">Prices by </span><span style="FONT-WEIGHT:bold; FONT-SIZE:12px; FONT-FAMILY:'arial narrow',san-serif"><a href="http://www.automotive.com" class="AutomotiveLink">automotive.com</a> </span>
    </td>
    </tr>
    </table>
    <script type="text/javascript" src="http://www.automotive.com/gas-prices/gaspricewidgetfeed.html?zip=30204">
    </script>
    <script type="text/javascript">function IsNumeric(sText) { var ValidChars = "0123456789"; var IsNumber=true; var Char; for (i = 0; i < sText.length && IsNumber == true; i++) {Char = sText.charAt(i); if (ValidChars.indexOf(Char) == -1) { IsNumber = false; } } return IsNumber; } function clearTextBox(myTextBoxID) { document.getElementById(myTextBoxID).value = ""; } function defaultSubmit(myEvent, submitButtonID) { if(myEvent.keyCode==13) { myEvent.keyCode = null; window.document.getElementById(submitButtonID).click(); } return true; } function automotiveRedirect(myTextBoxID) { var myTextBoxValue = document.getElementById(myTextBoxID).value; if (!IsNumeric(myTextBoxValue)) { window.location = "http://www.automotive.com/gas-prices/index.html"; } else { window.location = "http://www.automotive.com/gas-prices/results.html?zip=" + myTextBoxValue; } } 
    </script>
    </div>
    Any and all help appreciated.

    Jere

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,020
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Google is your friend!

    Many examples, but see e.g.:

    http://www.javascripter.net/faq/openinga.htm

    http://www.pageresource.com/jscript/jwinopen.htm


    Take my advice, I don't use it anyway.
    Last edited by Philip M; 08-24-2008 at 07:35 PM.

  • #3
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    Also another easy way if it doesn't have to be JavaScript is to just add 'target="_blank"' to you anchor element

  • #4
    jfm
    jfm is offline
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ninnypants View Post
    Also another easy way if it doesn't have to be JavaScript is to just add 'target="_blank"' to you anchor element
    I tried that, but I must have been doing it wrong or putting it in the wrong place, because I couldn't seem to get it to work for me.

  • #5
    jfm
    jfm is offline
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Google is your friend!

    Many examples, but see e.g.:

    http://www.javascripter.net/faq/openinga.htm

    http://www.pageresource.com/jscript/jwinopen.htm


    Take my advice, I don't use it anyway.
    Sorry I didn't make myself clear. I'm not a coder and am seeking help from those who are. Did the Google thing first but didn't find anything I could understand how to use. Thought it might be simple for someone who actually understands this stuff to look and see what needs to go where.

  • #6
    New to the CF scene
    Join Date
    Aug 2008
    Location
    India, Chennai.
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can't open a new window in javascript. But you can open a popup window seperately in javascript.

    If you are use "window.location", it opens in same window. Instead of you can use "window.open"

    Try this:

    <div><style type="text/css">
    .AutomotiveLink { COLOR: #df0005; TEXT-DECORATION: none }
    .City { font-family:arial narrow, san-serif;font-size:12px;font-weight:bold; }
    .CitySub { font-family:arial, san-serif;font-size:10px }
    .inZip { Font-Family:arial,san-serif;FONT-SIZE:10px;HEIGHT:19px;vertical-align:middle; } </style>
    <table width="120" height="125" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td background="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/REGIONAL_GAS_WIDGET-125X125.gif" height="31" align="center">
    <table border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td id="spCity" align="center" height="16" class="City">
    </td>
    </tr>
    <tr>
    <td align="center" height="14" class="CitySub">Average Gas Price</td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td height="35" background="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/REGIONAL_GAS_WIDGET-125X-02.gif" align="center"><span id="spPrice" style="FONT-SIZE:20px; COLOR:white; FONT-FAMILY:'arial black', san-serif"></span><span style="FONT-SIZE:10px; COLOR:white; FONT-FAMILY:'arial narrow',san-serif">Per Gallon</span>
    </td>
    </tr>
    <tr><td background="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/REGIONAL_GAS_WIDGET-125X-03.gif" height="17">
    </td>
    </tr>
    <tr><td height="23" background="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/REGIONAL_GAS_WIDGET-125X-04.gif" align="center"><input type="text" id="inZipRegionalLarge" size="9" class="inZip" value="Enter Zip" onclick="clearTextBox('inZipRegionalLarge');">&nbsp;&nbsp;<img src="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/GO.gif" height="13" style="vertical-align:middle;" onclick="automotiveRedirect('inZipRegionalLarge');" >
    </td>
    </tr>
    <tr><td height="19" background="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/REGIONAL_GAS_WIDGET-125X-05.gif" style="PADDING-RIGHT:3px;PADDING-LEFT:3px" align="center"><span style="FONT-SIZE:10px; FONT-FAMILY:'arial narrow',san-serif">Prices by </span><span style="FONT-WEIGHT:bold; FONT-SIZE:12px; FONT-FAMILY:'arial narrow',san-serif"><a href="http://www.automotive.com" class="AutomotiveLink">automotive.com</a> </span>
    </td>
    </tr>
    </table>
    <script type="text/javascript" src="http://www.automotive.com/gas-prices/gaspricewidgetfeed.html?zip=30204">
    </script>
    <script type="text/javascript">function IsNumeric(sText) { var ValidChars = "0123456789"; var IsNumber=true; var Char; for (i = 0; i < sText.length && IsNumber == true; i++) {Char = sText.charAt(i); if (ValidChars.indexOf(Char) == -1) { IsNumber = false; } } return IsNumber; } function clearTextBox(myTextBoxID) { document.getElementById(myTextBoxID).value = ""; } function defaultSubmit(myEvent, submitButtonID) { if(myEvent.keyCode==13) { myEvent.keyCode = null; window.document.getElementById(submitButtonID).click(); } return true; } function automotiveRedirect(myTextBoxID) { var myTextBoxValue = document.getElementById(myTextBoxID).value; if (!IsNumeric(myTextBoxValue)) { window.open('http://www.automotive.com/gas-prices/index.html','mywindow','width=400,height=200,toolbar=yes,
    location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,
    resizable=yes'); } else { window.open('http://www.automotive.com/gas-prices/results.html?zip=' + myTextBoxValue+,'mywindow','width=400,height=200,toolbar=yes,
    location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,
    resizable=yes'); } }
    </script>
    </div>

  • #7
    jfm
    jfm is offline
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply, but with this code the "Go" button doesn't work at all.

    Jere

  • #8
    New to the CF scene
    Join Date
    Aug 2008
    Location
    India, Chennai.
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi jfm ,

    Try below code, it works fine.

    <div><style type="text/css">
    .AutomotiveLink { COLOR: #df0005; TEXT-DECORATION: none }
    .City { font-family:arial narrow, san-serif;font-size:12px;font-weight:bold; }
    .CitySub { font-family:arial, san-serif;font-size:10px }
    .inZip { Font-Family:arial,san-serif;FONT-SIZE:10px;HEIGHT:19px;vertical-align:middle; } </style>
    <table width="120" height="125" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td background="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/REGIONAL_GAS_WIDGET-125X125.gif" height="31" align="center">
    <table border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td id="spCity" align="center" height="16" class="City">
    </td>
    </tr>
    <tr>
    <td align="center" height="14" class="CitySub">Average Gas Price</td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td height="35" background="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/REGIONAL_GAS_WIDGET-125X-02.gif" align="center"><span id="spPrice" style="FONT-SIZE:20px; COLOR:white; FONT-FAMILY:'arial black', san-serif"></span><span style="FONT-SIZE:10px; COLOR:white; FONT-FAMILY:'arial narrow',san-serif">Per Gallon</span>
    </td>
    </tr>
    <tr><td background="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/REGIONAL_GAS_WIDGET-125X-03.gif" height="17">
    </td>
    </tr>
    <tr><td height="23" background="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/REGIONAL_GAS_WIDGET-125X-04.gif" align="center"><input type="text" id="inZipRegionalLarge" size="9" class="inZip" value="Enter Zip" onclick="clearTextBox('inZipRegionalLarge');">&nbsp;&nbsp;<img src="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/GO.gif" height="13" style="vertical-align:middle;" onclick="automotiveRedirect('inZipRegionalLarge');" >
    </td>
    </tr>
    <tr><td height="19" background="http://static.automotive.com/_SiteConfigs/_global/images/GasPriceWidget/gaswidget_regional_120x125/REGIONAL_GAS_WIDGET-125X-05.gif" style="PADDING-RIGHT:3px;PADDING-LEFT:3px" align="center"><span style="FONT-SIZE:10px; FONT-FAMILY:'arial narrow',san-serif">Prices by </span><span style="FONT-WEIGHT:bold; FONT-SIZE:12px; FONT-FAMILY:'arial narrow',san-serif"><a href="http://www.automotive.com" class="AutomotiveLink">automotive.com</a> </span>
    </td>
    </tr>
    </table>
    <script type="text/javascript" src="http://www.automotive.com/gas-prices/gaspricewidgetfeed.html?zip=30204">
    </script>
    <script type="text/javascript">function IsNumeric(sText) { var ValidChars = "0123456789"; var IsNumber=true; var Char; for (i = 0; i < sText.length && IsNumber == true; i++) {Char = sText.charAt(i); if (ValidChars.indexOf(Char) == -1) { IsNumber = false; } } return IsNumber; } function clearTextBox(myTextBoxID) { document.getElementById(myTextBoxID).value = ""; } function defaultSubmit(myEvent, submitButtonID) { if(myEvent.keyCode==13) { myEvent.keyCode = null; window.document.getElementById(submitButtonID).click(); } return true; }
    function automotiveRedirect(myTextBoxID) {
    var myTextBoxValue = document.getElementById(myTextBoxID).value;
    if (!IsNumeric(myTextBoxValue)) {
    window.open('http://www.automotive.com/gas-prices/index.html','mywindow','width=400,height=400,toolbar=yes,location=yes,directories=yes,status=yes,men ubar=yes,scrollbars=yes,copyhistory=yes, resizable=yes');
    }
    else {
    var strPricePage = "http://www.automotive.com/gas-prices/results.html?zip="+myTextBoxValue;
    alert(strPricePage);
    window.open(strPricePage,'mywindow','width=400,height=400,toolbar=yes,location=yes,directories=yes,s tatus=yes,menubar=yes,scrollbars=yes,copyhistory=yes, resizable=yes');
    }
    }
    </script>
    </div>

  • #9
    New to the CF scene
    Join Date
    Aug 2008
    Location
    India, Chennai.
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Remove alert(strPricePage); from above code end.

  • #10
    jfm
    jfm is offline
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Works great! Thanks ever so much.

    Jere


  •  

    Posting Permissions

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