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
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to make URL link that uses Javascript work if Javascript is disabled?

    Does anyone know how to make URL links that use Javascript still work when
    users have Javascript disabled on their browser?

    The only reason I'm using JS on a URL is because my link opens a PDF file, and I'm forcing it not to cache so users have the latest version.

    I tried the <script><noscript> tags, but I'm not sure if I'm using it
    correctly, as my URL completely disappears.

    Below is my HTML/Javascript code:

    <p class="download">
    <script type="text/javascript">document.write("<span
    style=\"text-decoration: underline;\"><a href=\"javascript:void(0);\"
    onclick=\"window.open(
    'http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf?nocache='+
    Math.floor( Math.random()*11 ) );\" >The Child Magazines Media
    Kit</a></span> (PDF 1 MB) ");</script>
    <noscript><span style="text-decoration: underline;"><a
    href="http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf"
    >The Child Magazines Media Kit</a></span> (PDF 1 MB)</noscript>
    </p>


    Thanks for any help,
    Michael

  • #2
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    945
    Thanks
    0
    Thanked 129 Times in 128 Posts
    You use <script><noscript> the right way.

    But there is no reason for style the spans with text-decoration.
    The only content it has is a link that by default is underline.

    In fact you do not need the spans at all here.

    Code:
    <p class="download">
    <script>
    document.write('<a href="javascript:void(0);" onclick="window.open(\'http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf?nocache=\'+Math.floor( Math.random()*11 ) );">The Child Magazines Media Kit</a> (PDF 1 MB) ");
    </script>
    <noscript>
    <a href="http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf">The Child Magazines Media Kit</a> (PDF 1 MB)
    </noscript>
    </p>
    will suffice

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,640
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by lerura View Post
    You use <script><noscript> the right way.

    But there is no reason for style the spans with text-decoration.
    The only content it has is a link that by default is underline.

    In fact you do not need the spans at all here.

    Code:
    <p class="download">
    <script>
    document.write('<a href="javascript:void(0);" onclick="window.open('http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf?nocache='+Math.floor( Math.random()*11 ) );">The Child Magazines Media Kit</a> (PDF 1 MB) ");
    </script>
    <noscript>
    <a href="http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf">The Child Magazines Media Kit</a> (PDF 1 MB)
    </noscript>
    </p>
    will suffice
    That's the 1996 way of doing it. You don't need to use either of the antiquated commands document.write or <noscript> to do this.

    The following is all that you need to do it:

    Code:
    <a
     href="http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf"
     onclick="window.open(\'http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf?nocache=\'+Math.floor( Math.random()*11 ) );return false;">The Child Magazines Media Kit</a>
    Note that the onclick simply needs to return false to prevent the href being followed.
    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.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,045
    Thanks
    0
    Thanked 251 Times in 247 Posts
    No need to specify the URL twice and escape the single quotes.

    Code:
    <a href="http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf"
     onclick="window.open(this.href + '?nocache=' + Math.floor( Math.random()*11 ) );return false;">The Child Magazines Media Kit</a>


  •  

    Tags for this Thread

    Posting Permissions

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