Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-13-2012, 03:20 AM   PM User | #1
mbborromeo
New to the CF scene

 
Join Date: Apr 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
mbborromeo is an unknown quantity at this point
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
mbborromeo is offline   Reply With Quote
Old 04-13-2012, 04:07 AM   PM User | #2
Lerura
Regular Coder

 
Lerura's Avatar
 
Join Date: Aug 2005
Location: Denmark
Posts: 869
Thanks: 0
Thanked 112 Times in 111 Posts
Lerura will become famous soon enough
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
Lerura is offline   Reply With Quote
Old 04-13-2012, 10:03 AM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,452
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Old 04-13-2012, 12:43 PM   PM User | #4
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
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>
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Reply

Bookmarks

Tags
disabled, javascript, link, noscript, url

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:48 AM.


Advertisement
Log in to turn off these ads.