TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-10-2008, 04:23 AM   #1 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default 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 is offline  
Reply With Quote
Old 06-10-2008, 04:47 AM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Oy, I'm an idiot. Nevermind, it's just been ten years since I've used <noscript>. -m
delayedinsanity is offline  
Reply With Quote
Old 06-10-2008, 11:06 AM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-10-2008, 02:37 PM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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
delayedinsanity is offline  
Reply With Quote
Old 06-10-2008, 03:52 PM   #5 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

Javascript shouldn't need <noscript>...
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 06-10-2008, 04:45 PM   #6 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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
delayedinsanity is offline  
Reply With Quote
Old 06-10-2008, 04:49 PM   #7 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

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)
sketchMedia is offline  
Reply With Quote
Old 06-10-2008, 06:11 PM   #8 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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.
Attached Files
File Type: html javascript-example.html (533 Bytes, 187 views)
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
delayedinsanity (06-10-2008)
Old 06-10-2008, 06:14 PM   #9 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

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.
xenon is offline  
Reply With Quote
Old 06-10-2008, 07:23 PM   #10 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by delayedinsanity View Post
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
Orc is offline  
Reply With Quote
Old 06-10-2008, 07:51 PM   #11 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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.
delayedinsanity is offline  
Reply With Quote
Old 06-10-2008, 09:04 PM   #12 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

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.
xenon is offline  
Reply With Quote
Old 06-10-2008, 09:23 PM   #13 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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
delayedinsanity is offline  
Reply With Quote
Old 06-11-2008, 08:40 AM   #14 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

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)
sketchMedia is offline  
Reply With Quote
Old 06-11-2008, 08:17 PM   #15 (permalink)
The Contributor
 
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
SpYkE112 is on a distinguished road
Default

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! :|
SpYkE112 is offline  
Reply With Quote
Old 06-11-2008, 08:45 PM   #16 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

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.
xenon is offline  
Reply With Quote
Old 06-12-2008, 08:12 AM   #17 (permalink)
The Contributor
 
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
SpYkE112 is on a distinguished road
Default

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
SpYkE112 is offline  
Reply With Quote
Old 06-12-2008, 09:02 AM   #18 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

You can write PHP in so many ways and it will still work. ;)
Salathe is offline  
Reply With Quote
Old 06-12-2008, 09:52 AM   #19 (permalink)
The Contributor
 
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
SpYkE112 is on a distinguished road
Default

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
SpYkE112 is offline  
Reply With Quote
Old 06-12-2008, 10:01 AM   #20 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

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);
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 01:24 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design