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
    Regular Coder
    Join Date
    Oct 2009
    Posts
    455
    Thanks
    7
    Thanked 3 Times in 3 Posts

    how to get hyperlink to open blank target if noscript

    I have a hyperlink that would normally open a photo album script using the onclick, but if JS is turned off I would like the link to open the image in a blank page and not in the same window, for the visitor to close it not knowing that it was in the same window, therefore losing the visitor.

    What method could I do this in?

    I tried to add it in like so, but it did not work, and only shows all the hyperlink code in the page instead.

    Code:
    <a <noscript>target="_blank" </noscript>href="images/<? echo($imageFile); ?>" class="highslide" onclick="return hs.expand(this)">

  • #2
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,718
    Thanks
    0
    Thanked 240 Times in 235 Posts
    Hi there needsomehelp,

    there is no need to use the "noscript element".

    If javascript is disabled the link will work as normal.

    Here is an example for you to test my assertion...
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html lang="en">
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="language" content="english"> 
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    
    <title>javascript or no javascript</title>
    
    <script type="text/javascript">
    
    function init(){
    document.getElementById('mylink').onclick=function() {
       expand(this);
       return false;
      }
     }
    function expand(obj){
       alert('this is javascript and the "this" is...\n\n' +obj);
     }
       window.addEventListener?
       window.addEventListener('load',init,false):
       window.attachEvent('onload',init);
    </script>
    
    </head>
    <body>
    
    <div>
    <a id="mylink" href="http://www.coothead.co.uk/images/blood.jpg" target="blank">Do javascript or don't do javascript</a>
    </div>
    
    </body>
    </html>
    
    coothead

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,784
    Thanks
    6
    Thanked 1,022 Times in 995 Posts
    To expand on this: Using progressive enhancement you would have the default behavior of the link to open in a new window and remove that behavior with JavaScript.

  • #4
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks


  •  

    Posting Permissions

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