 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
06-10-2008, 04:23 AM
|
#1 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
If no javascript??
Say I have a link that looks like this:
<a href="javascript:;" onclick="dosomething()">
How can I have it default to a normal href if javascript is disabled? I know it's probably a stupid question but I'm really javascript dumb... I want it to link to a normal page.php if the javascript is disabled in the remote browser.
-m
|
|
|
|
06-10-2008, 04:47 AM
|
#2 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Oy, I'm an idiot. Nevermind, it's just been ten years since I've used <noscript>. -m
|
|
|
|
06-10-2008, 11:06 AM
|
#3 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
My apologies for resurrecting this thread, but I think it brings up some important discussion points. Delete it, however, if you wish.
I would use something like the following in lieu of the <noscript> tag:
javascript Code:
pLink = document.getElementById('myLink'); pLink.setAttribute('href', 'http://www.talkphp.com/'); pLink.onclick = function() { alert('Do something fancy with javascript!'); }
I have never actually used the <noscript> tag, I must admit.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
06-10-2008, 02:37 PM
|
#4 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
No problem, I just took it down to quell the signal to noise ratio.
How does that work? I tried adding it to the head of a page wrapped in <script type="text/javascript"> and added a link with the ID myLink, but nothing, so I'm sure I'm missing something obvious. :P
-m
|
|
|
|
06-10-2008, 03:52 PM
|
#5 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
|
Javascript shouldn't need <noscript>...
__________________
Signatures are nothing but incriminating.
|
|
|
06-10-2008, 04:45 PM
|
#6 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
No, javascript itself shouldn't, but what about people browsing without javascript? For whatever reason, they have an obscure browser that doesn't support it, or they have it turned off, or...
I've been to a lot of sites, and I'm sure most of you have been too, that break horribly without javascript being enabled. There is absolutely no graceful degradation, you either have it on, or you don't use that site. I've seen some where it breaks something so obviously necessary as the ability to log in, and others where it breaks little things, that chances are the site was better off without anyways.
I like AJAX, I think it's nifty, and can be enormously handy in some cases. But anything I use javascript for, I want to make sure there's something in place to handle the situation if there is no javascript.
-m
|
|
|
|
06-10-2008, 04:49 PM
|
#7 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
put the script after the element definition, i.e. before the closing body tag, otherwise it wont exist to it.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
06-10-2008, 06:11 PM
|
#8 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
My code would only be executed if the end user has JavaScript enabled. If there is no JavaScript then they would simply see the HTML version. Take my little example, if you have JavaScript enabled then the link will take you to Google upon confirmation. If not it will degrade nicely and take you straight to Google without a prompt.
Edit: Or of course I could just return true upon confirmation. Either way.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
|
The Following User Says Thank You to Wildhoney For This Useful Post:
|
|
06-10-2008, 06:14 PM
|
#9 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
That's the most stupid method you could use. The right way:
Code:
<a href="destination-page.html" onclick="dosomething(); return false;">some link</a>
The return statement in the onclick action is the most important. If you have javascript, then the dosomething function will be executed, and that's it. If you don't have javascript, however, the browser will ignore the onclick attribute and follow the href attribute.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
|
|
|
|
06-10-2008, 07:23 PM
|
#10 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by delayedinsanity
Oy, I'm an idiot. Nevermind, it's just been ten years since I've used <noscript>. -m
|
How old are you?
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
06-10-2008, 07:51 PM
|
#11 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
I'm 12. And who are you referring to, regarding the most stupid method xenon? Moi? It may be, I won't disagree with that. As I've stated I'm javascript stupid. I could, and probably should go and do at least some basic tutorials to get my feet wet with it again, but I've got so much on my plate that I'm avoiding that for right now. Not a good excuse, but a valid one. Thank you everybody for the help here. -m EDIT: seriously, vBulletin is removing all my line breaks and just being odd right now.
|
|
|
|
06-10-2008, 09:04 PM
|
#12 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
I was referring to the <noscript> method. Wildhoney posted a similar solution, but he did that while I was still writing my post 
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
|
|
|
|
06-10-2008, 09:23 PM
|
#13 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
I happen to like the noscript method. It makes things complicated and highly obfuscated, which is my silent outcry against usability twits like Jakob Nielsen and Jukka Korpela who think everything on the web needs to be ONE way or no way at all. *runs str_shuffle on all his html*
-m
|
|
|
|
06-11-2008, 08:40 AM
|
#14 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
well to say <noscript> is stupid is alittle strong, but it is entirly unnecessary as javascript should only act as an enhancement to the current functionality of the site, therefore if javascript is disabled the site will still work without the need for noscript.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
06-11-2008, 08:17 PM
|
#15 (permalink)
|
|
The Contributor
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
|
In my oppinion Javascript comes straight from hell, it introduces nothing but complication and security breachs. Plus, you take the risk of haveing a piece of Javascript that runs perfectly on IE but breaks on FF or Opera og whatever.. Which i find rather sucky! :|
|
|
|
|
06-11-2008, 08:45 PM
|
#16 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
Spyke, you don't NEED to use Javascript. Security breaches and cross-browser incompatibilities come from the developer not understanding correctly Javascript or misusing it. So, you can stop blaming something you know nothing about.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
|
|
|
|
06-12-2008, 08:12 AM
|
#17 (permalink)
|
|
The Contributor
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
|
I don't use it, but i still don't like that everyone seems to love it, and for the most part people can't use it "right", you can write Javascript in so many ways, and it will still work.. That is what i dislike :)
And i know stuff about Javascript :P
|
|
|
|
06-12-2008, 09:02 AM
|
#18 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
You can write PHP in so many ways and it will still work. ;)
|
|
|
|
06-12-2008, 09:52 AM
|
#19 (permalink)
|
|
The Contributor
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
|
Yes, but what i mean is that Javascript isn't as consequent (spelling xD) as PHP.
Fx. in PHP you have to end most lines with a semicolon you don't HAVE to in Javascript, but you can? What is that all about :P
|
|
|
|
06-12-2008, 10:01 AM
|
#20 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
You should be using a framework such as mootools to get rid of the many cross browser issues. MooTools "normalizes" alot of standard methods that some browsers may not have or is named differently.
But its also limited what I've run into with cross browser javascript issues even on more advanced tasks, the only potential thing I find is the Mozilla's .textContent vs. the .innerText one. Ofcourse you can say like:
var text = (element.textContent || element.innerText);
__________________
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|