Determining which href tag to show based on if JS is enabled or not

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
I have a problem where I have to loop through a set of photos and generate <a href> tags for each one that is displayed. However, the link that is displayed is going to depend on whether or not javascript is enabled. So I'm trying to figure out which way to make this happen is the best practice.

My first thought is to simply declare the <a href> as I would if JS wasn't enabled (as well as include an id in the tag) and then write some JS that swaps the a href tag for the JS enabled one. Any body have any better ideas?
 

sourceninja

Diamond Member
Mar 8, 2005
8,805
65
91
How would you create the HREF tags if javascript was not enabled without doing it the way you suggested?
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
In theory you could do something to figure out if javascript was enabled, remember that server-side, and generate the appropriate links server-side from that point forward. It's an awful idea for a handful of reasons, but just throwing it out there.