TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Javascript, AJAX, E4X (http://www.talkphp.com/javascript-ajax-e4x/)
-   -   If no javascript?? (http://www.talkphp.com/javascript-ajax-e4x/2941-if-no-javascript.html)

delayedinsanity 06-10-2008 04:23 AM

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

delayedinsanity 06-10-2008 04:47 AM

Oy, I'm an idiot. Nevermind, it's just been ten years since I've used <noscript>. -m

Wildhoney 06-10-2008 11:06 AM

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.

delayedinsanity 06-10-2008 02:37 PM

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 &lt;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

Aaron 06-10-2008 03:52 PM

Javascript shouldn't need <noscript>...

delayedinsanity 06-10-2008 04:45 PM

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

sketchMedia 06-10-2008 04:49 PM

put the script after the element definition, i.e. before the closing body tag, otherwise it wont exist to it.

Wildhoney 06-10-2008 06:11 PM

1 Attachment(s)
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.

xenon 06-10-2008 06:14 PM

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.

Orc 06-10-2008 07:23 PM

Quote:

Originally Posted by delayedinsanity (Post 15497)
Oy, I'm an idiot. Nevermind, it's just been ten years since I've used <noscript>. -m

How old are you?

delayedinsanity 06-10-2008 07:51 PM

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.

xenon 06-10-2008 09:04 PM

I was referring to the <noscript> method. Wildhoney posted a similar solution, but he did that while I was still writing my post :-P

delayedinsanity 06-10-2008 09:23 PM

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

sketchMedia 06-11-2008 08:40 AM

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.

SpYkE112 06-11-2008 08:17 PM

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! :|

xenon 06-11-2008 08:45 PM

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.

SpYkE112 06-12-2008 08:12 AM

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

Salathe 06-12-2008 09:02 AM

You can write PHP in so many ways and it will still work. ;)

SpYkE112 06-12-2008 09:52 AM

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

Kalle 06-12-2008 10:01 AM

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);


All times are GMT. The time now is 08:50 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0