CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   How to make URL link that uses Javascript work if Javascript is disabled? (http://www.codingforums.com/showthread.php?t=257130)

mbborromeo 04-13-2012 03:20 AM

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

Lerura 04-13-2012 04:07 AM

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

felgall 04-13-2012 10:03 AM

Quote:

Originally Posted by lerura (Post 1215578)
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.

glenngv 04-13-2012 12:43 PM

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>



All times are GMT +1. The time now is 05:18 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.