Consider this post more of a therapy session. I have this anti-javascript attitude that I've been carrying around with me for awhile and I really don't know why.
It's not that I don't understand javascript or don't think it's useful. Maybe my fear of it is based on other peoples opinions about it. As I write this, I'm recalling people I've encountered who have used phrases such as "evil javascript" or "eww, javascript" or "insecure javascript" when discussing web development.
Or maybe I avoid using javascript because of accessibility issues, meaning that a user can disable javascript in their browser if they choose. In doing so, part of my application is now useless to that user.
For whatever reasons I have been avoiding using javascript, I would like your thoughts on it. Do you avoid it too? If so, why? Or are you of the opposite frame of mind - you love to use javascript in your web development? Or maybe you use it only when necessary. Either way, I'd appreciate your thoughts.
Thanks,
*Nick*
leatherback
02-21-2007, 08:32 PM
I personally do not like javascript. As you mentioned: People can have it switched off. Another browser may not understand it, and really.. When you want to be sure that something works.. Do it on the server, where YOU control what is interpreted how.
However, in some non-crucial situations (e.g., p[re-checking formfields) you could implement it. I personally don't. I rather feed back the form with selected options included than try to get a cross-browser valid JS to work.
EPJS
02-21-2007, 08:47 PM
The *only* time I use JavaScript is when I am able to leave a fallback to those with JS turned off. I avoid using JS if a fallback can't be provided.
Here's an example of JS with a fallback:
<a href='#top' onclick='scroll(0,0); return false;'>Top of page</a>
With JS on it will just jump to the top of the page, with JS off it will jump to the bookmarked section of my site where #top is identified (in this case, at the top of the page)
Here's an example of "bad JS" (no fallback):
<a href='javascript:scroll(0,0)'>Top of page</a>
In this case, if JS is turned off the link won't work.
xblue
02-22-2007, 04:30 AM
In my opinion, javascript is good for add-on features that may facilitate things but are in no way essential to use whatever the website offers.
Sometimes there are official recommendations to disable javascript because of some unpatched security issue, which always makes me mad because there are a lot of popular websites like airlines that would not even let you book a flight without javascript.
stolzyboy
02-22-2007, 11:30 AM
it also is important if you know who your target audience is... where i work, i know who the users are and i know they aren't able to change anything in their browser, it's all controlled and the sites are used internally so we can use any/all JS stuff we want, so that is another factor you can think about...
as general web development where you can't control the target audience, i tend to stay away from JS
hth,
stolzyboy
Piranha
02-22-2007, 11:40 AM
I would not have a problem with using JS for web development as long as it is not the only way to do something. And never trust the client to have it turned on. Using it to validate input data before it is sent (checking it again in PHP), creating a drop-down menu or other stuff is ok as long as you make sure that it is easy to use the site without JS as well.
Having said that I haven't gotten around to learn JS, so I'm not using it.
kebbelj
02-22-2007, 12:52 PM
I LOVE Javascript for the following reasons.
1. It is an excellent tool for teaching computer programming to public school students.
a. Every kid who has a computer has the tool to write (any text editor) and interpret their scripts (any web browser)
b. It is simpler to learn and teach than C, C++, Java, etc.
c. Though it is easier than C, C++, Java, etc., a large part of Javascript--loops and branch structures--is almost identical to these more complex languages. Learning Javascript gives you a toehold in all these other languages.
2. You can accomplish wonders with Javascript using the client's processor.
3. Javascript applications are portable. Matrixes can store small, internal databases that can be picked up and moved without breaking any MySQL/text file connection.
4. While Javascript being turned off may hamper web applications, that can be a non-issue inside an intranet. Your web applications are lightning-fast (they're inside the web page) and accessible to everyone.
Weedpacket
02-22-2007, 06:59 PM
As already observed, the main barrier to using Javascript is that it isn't necessarily available on the client, and so any functionality needs a non-JS workaround (though how many JS-using sites, legal requirements notwithstanding, actually do that?)
If you can be assured of Javascript functionality then it's invaluable; especially in recent years when it got a standardised API into the DOM instead of the masses of ad hoc flakery that used to be the norm.
A lot of the typical cosmetic stuff that Javascript is used for (pop-up menus and the like) could also be done using CSS (which is generally a faster and cleaner approach anyway). Unfortunately, there are still too many copies of Internet Explorer with hopeless CSS support floating around to do this without tiresome IE-specific CSS hacks (like IE7 still doesn't support the :hover pseudoelement on non-<a> tags).
greenie2600
03-01-2007, 02:26 PM
JavaScript has a bad rap. It's been crippled for years by shoddy implementations and the widespread use of amateur cut-and-paste code, but it's really started coming into its own as a programming language. I've come to love it over the past few months - though, like any tool, you must understand its limitations to use it effectively. And, of course, it's vital if you're doing anything with AJAX.
If you plan on doing any serious JavaScript programming, I highly recommend using Firefox (for its actually-useable JavaScript console) with the Web Developer Toolbar add-on (for its "View Generated Source" function). (Of course, you'll want to test things in IE6 and IE7 to make sure they work, but as a development and debugging tool, Firefox is far superior.)
Thanks to these tools and the recent trend toward standardized implementations of JavaScript and the DOM, it's actually possible to write complex, robust, scalable JavaScript that never throws an error. As you and others have pointed out, it's not appropriate for every situation, but if you can be confident that all of your users will have JavaScript enabled (such as when writing an intranet app) or if you're only using it to provide enhanced functionality, it can be very useful. The principles of unobtrusive JavaScript (Google it - it basically boils down to the separation of the presentation/content layer of a page from the behavior layer) help greatly in this area.
As an example of what I mean by "enhanced functionality", I recently wrote a JavaScript class that finds every <input type="text"> field with a class of "date". For each one, it inserts a little calendar icon next to the field; clicking on the icon brings up a little calendar, from which you can select a date. Users who don't have JavaScript simply don't see the icon; they can still enter dates manually. I have another class that adds a little expand/collapse icon to any <fieldset> with the class "collapsible" - again, users without JavaScript just see a regular <fieldset>. Autocompleting text fields would be another example. Once you have a few classes like these, it's very easy to create rich, gracefully degrading interfaces without adding a single line of JavaScript to your HTML code.
Azala
03-01-2007, 05:10 PM
I guess it comes down to where you live in the world.
In Norway people expect cutting edge technology and user functionality, hard to accomplish without using javascript/ajax etc.
People couldn't give a rats ass about their site being compatible with NS4 and frankly, how are you ever going to learn something new, and possibly make something exceptionally cool, if you are constantly held back by the fear of not being compatible with the last guy to upgrade.
Get your hands on some solid statistics and concentrate on the majority of your users, making their experience mind blowing instead of catering to every possible combo out there can be just as rewarding.
NogDog
03-02-2007, 02:35 AM
I guess it comes down to where you live in the world.
In Norway people expect cutting edge technology and user functionality, hard to accomplish without using javascript/ajax etc.
People couldn't give a rats ass about their site being compatible with NS4 and frankly, how are you ever going to learn something new, and possibly make something exceptionally cool, if you are constantly held back by the fear of not being compatible with the last guy to upgrade.
Get your hands on some solid statistics and concentrate on the majority of your users, making their experience mind blowing instead of catering to every possible combo out there can be just as rewarding.
I don't think it's as much an issue of people using old browsers as it is of people turning JS off even in modern browsers. Whether or not turning JS off is a misguided attempt at increasing security, a sign of ignorance, or an indicator that they know something that the vast majority do not; the fact remains that some people do not have JS running on their browsers.
So if you assume that some small percentage of your site's visitors may not have JS, you need to decide if you need to cater to them, or ignore them. If the purpose of your site is simply "making their experience mind blowing", then by all means ignore them. If your purpose is to sell a product and you are not crazy about losing 5%, 3%, or even 1% of your potential sales due to a need to use all the coolest "gee-whiz" client-side effects, then you need to either eschew using JS, or if you do use it (which can have many valid advantages to helping make sales to the vast majority of users who do have JS enabled), then you need to put in some additional effort to ensure that your site is usable by those with non-JS user clients.
But it's all a matter of priorities: what you want to accomplish with your site, what the best estimate is of users who don't have JS enabled who might be potential users/customers on your site, and then weighing those and any other related factors to decide what the best design and implementation choices should be for each particular situation.
Weedpacket
03-02-2007, 04:13 AM
Google doesn't do Javascript. You don't want to upset Google.
Azala
03-02-2007, 05:27 AM
I can make up any potentional statistics I want.
- I may loose 5% sales if I go for a solid old look work in all browsers solution because the user found it hard to navigate.
- I may gain 5% sales if I go for the latest technology, but lose the potentional big sale because some guy at some company who wanted to place a huge order was still using pen and paper...
...and I could go on and on making up what could be or not...
That is why I say get your hands on solid statistics, with that you can tailor your site into whatever your users want to see.
Again, it's impossible to please everyone, it's impossible to design something that would ensure maximum sales for everyone everywhere in the world.
Go with the majority :)
P.S Don't forget some of us are actually on a budget with our clients, we got a certain amount of time to accomplish something with the money we're being payed, make the most of it.
EPJS
03-02-2007, 10:12 PM
creating a drop-down menu
What I find annoying is when people use JS in drop-downs, when it is soooooo easy to make a drop-down that doesn't require JS.
In fact, it's about twice as easy to make a drop-down with no JS than it is to make one with JS.... yet some people are too "JS happy" I suppose. :rolleyes:
EPJS
03-02-2007, 10:27 PM
Whether or not turning JS off is a misguided attempt at increasing security, a sign of ignorance, or an indicator that they know something that the vast majority do not
I use the "no-script" extension for Firefox to chose which sites to allow to use JS (off on all sites by default[I allow it on this site btw]) because some sites are just so bloody annoying with JS on. There are some sites with endless alert pop-ups, sites that adjust your browser window, sites that disable your context menu (right-click menu). So many annoyances JS can bring.
Weedpacket
03-03-2007, 04:58 AM
In fact, it's about twice as easy to make a drop-down with no JS than it is to make one with JS.... And let's not start in on the people who make it in Flash.
I've seen Flash used for two-frame image button rollovers. Really. What was that about working within budgets? :)
EPJS
03-03-2007, 02:39 PM
lol that's a really pointless piece of Flash. Image rollovers can be done in either JS or CSS (I prefer to use the CSS approach).
NogDog
03-03-2007, 04:13 PM
lol that's a really pointless piece of Flash. Image rollovers can be done in either JS or CSS (I prefer to use the CSS approach).
Would you care to share with us your secret to creating JavaScript-free drop-downs. I know how to do them with CSS, but you always have to add at least a little JS so that the ignorant IE browsers can deal with the concept of :hover pseudo-classes used on elements other than <a>.
madwormer2
03-03-2007, 06:46 PM
<select>?
Maybe that's what he means, maybe not :P
I still use document.all, so what do I know ;)
Weedpacket
03-03-2007, 09:09 PM
:hover pseudo-classes used on elements other than <a>.Probably a matter of wrapping the rollover in an <a> tag and attaching the CSS rules to that. (And IE7 still doesn't do :hover right. Sheesh, what do they spend their time doing over there in Redmond?)
EPJS
03-03-2007, 10:23 PM
Weedpacket is right about the rollovers. Just make sure they are withing an <a> tag so they work on IE.
NogDog, you can make a drop-down Navigation system that doesn't require JS by using PHP. <form>,<select>,<input>
I can make an example page if you want to see it in action?
EPJS
03-03-2007, 11:04 PM
Here, I just finished writing the script for the "no js" navigation system.
http://media.xenweb.net/navtest.php
Source code printed on the page as well as an active example.
NogDog
03-03-2007, 11:11 PM
Here, I just finished writing the script for the "no js" navigation system.
http://media.xenweb.net/navtest.php
Source code printed on the page as well as an active example.
OK, a minor misunderstanding, then. I thought you were talking about client-side hierarchical pop-up menus such as "suckerfish" dropdowns (http://alistapart.com/articles/dropdowns/).
NogDog
03-03-2007, 11:12 PM
Probably a matter of wrapping the rollover in an <a> tag and attaching the CSS rules to that. (And IE7 still doesn't do :hover right. Sheesh, what do they spend their time doing over there in Redmond?)
The problem with that is that it requires invalid [X]HTML code (block-level elements within an in-line element).
EPJS
03-03-2007, 11:19 PM
OK, a minor misunderstanding, then. I thought you were talking about client-side hierarchical pop-up menus such as "suckerfish" dropdowns (http://alistapart.com/articles/dropdowns/).
Oh. That is an interesting way to do it, using a list. I'll be sure to read that article :)
EPJS
03-03-2007, 11:29 PM
The problem with that is that it requires invalid [X]HTML code (block-level elements within an in-line element).
On http://www.cssplay.co.uk they show you a valid method for this.
I think Weedpacket meant one thing but said another. You don't "wrap" the rollover in <a>, you make the rollover with <a>
Here's a good example from that site http://www.cssplay.co.uk/menus/menutwelve.html
scrupul0us
03-05-2007, 10:13 AM
I REALLY try to avoid JS... idk, its just not something *i like*
i mean, to have to catch the DOM differently for all the diff browsers, come on!, that sucks!
php works across the board and i control it.. now, i do find JS useful as im getting into ajax, BUT, in every place that I load something with ajax i also provide a
so that if JS is disabled my content still loads... but yea... i think i stay away from it b/c it seems so foreign to me and my entire web life i've been so pro PHP that maybe ive become closed minded... i think i also have NO idea how the DOM actually works, so that hurts me as well.. i really need todo like i did for PHP and buy a book or two
dalecosp
03-06-2007, 05:04 PM
I appreciate some developers who've added useful features to sites using JS. But to break your own leg by not providing an alternate method of obtaining the functionality isn't a Good Thing(tm).
So, intranets and "extras", but the site must work without it. Did I hear an echo in here?
me 2, me2 ... mebbe i should go back to sleep or whatnot....
greenie2600
03-06-2007, 05:45 PM
scrupul0us -
1. I know you're well aware of this, but you can't really compare PHP and JavaScript. They're two different tools for two different purposes.
2. The DOM is really very simple. It's roughly comparable to a family tree. Every valid (X)HTML document can be represented as a hierarchical tree, with the <html> element at the root. Wherever one element (tag) is nested inside another (e.g., table rows nested inside a table, or a <strong> tag nested inside a <p>), the outermost element is said to be the "parent", and the innermost element is said to be the "child". Elements are also known as "nodes" of the DOM.
So the <html> element typically has two children: <head> and <body>. The <head>'s children, in turn, are usually <title>, <link>, <script>, and <meta> elements. And then the <body> has its own children—paragraphs, forms, tables—which have their own children, and so on.
Each node has a variety of properties, depending on what kind of element it is. These properties include the element's HTML attributes—value, action, method, class, style, and so forth—as well as numerous others which can't be represented directly in HTML.
Each node also has its own methods—which, again, vary depending on the type of element.
So every element (tag) in your document is represented by a node on the DOM, and every attribute is a property of its node. Essentially, the DOM (Document Object Model) is one giant object, which represents your HTML page.
JavaScript offers a wide variety of methods for finding your way around this tree ("walking" or "traversing" the DOM), and for inspecting and manipulating it (getting/setting the properties of a node, inserting/deleting nodes [e.g., table rows], and so forth.
The DOMs in modern browsers (Firefox and IE6/7, at least) are really quite standardized; once in a while, you'll run into a quirk, but the days of wildly divergent behavior in different browsers are pretty much behind us. Thank Ghod.
Weedpacket
03-06-2007, 09:53 PM
The DOMs in modern browsers (Firefox and IE6/7, at least) are really quite standardized; It's the same standard as employed by PHP's DOM extension, and is detailed (at least in part) here (http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/) (note the date).
pohopo
03-09-2007, 02:58 AM
So, intranets and "extras", but the site must work without it. Did I hear an echo in here?I disagree. You do not need to code a page for 100% of the users that browse the internet then you are going to have one plain page. I believe you should code for your audience. So if you are making a site for graphic designers you can probably be safe with a javascript site, but if you are making one for color blind people you should probably not have dark brown text with a dark red background. If it is for computer geeks you probably want it to work without javascript as you know a few of them will have it off to make a point.
dalecosp
03-09-2007, 09:43 AM
OK, so why do we have standards, then?
dougal85
03-11-2007, 11:22 PM
I've not quite read the whole thread so sorry for covering anything that's already been said. I only just noticed the thread.
Does anybody know any good websites for stats? % of people with JavaScript and other things like flash so they can be compared.
I've been doing my Honours (final year) Project on AJAX, the official title being "Web 2.0 and AJAX". Anyway, I have done a considerable bit of reading and testing with JavaScript.
Until fairly recently I thought JavaScript was bad, however... I actually now I really like it.
As for support, its pretty widespread now, but alternatives should always be available. I do wonder what percentage of people are using an even more horrible earlier version of IE? How far back in the IE world do you cater for?
The world has to move on eventually.
JavaScript has such a bad reputation because of how it came to be. It used to be seen as 'toy' and used for things like making buttons go pink - generally annoy the hell out of people.
In some ways I think its growth to be similar to PHP. I think there are problems with good coding practices and styles. Not that PHP used to annoy people, but it was originally designed for small things (Personal Home Page). My reference to PHP is a bit hesitant as I'm sure many people know the history of PHP better than me.
However, now I feel like PHP is growing up as a language (like PHP is). Of course there are still problems but there are also really well implemented websites.
Lots of the comments through this thread sound like; that would be better done in CSS or whatever. Well of course it is. The only real valid use JavaScript when it can add something nothing else can (or its just silly like doing it in flash)
but anyway...
Surely, JavaScript like any language (or almost anything in IT) if used correctly is great, if used in correctly can be dangerous. As web developers I think its good to get used to JavaScript... its here to stay (for a while at least). I'm sure its just going to grow in popularity as people demand it.
dougal85
03-11-2007, 11:41 PM
I believe you should code for your audience.
Just felt I had to reply to this...
That's the wonders of the web, your audience is the world. IE. everybody.
OK, fair enough, you might be running a business in a specific area so you don't care about languages and other cultures. but otherwise...
OK, I'm actually trying to think of an example, but they all sound so preposterous I've deleted it straight after I wrote it.... heck, I'll just go with the first thing that comes out my head.
OK, graphic designer website... yup, javascript is OK.
what if you have a geeky graphics designer?
what if you have a colour blind graphics designer? (I'm sure one exists! but i guess it could be hard for them!)
What if you have a graphics designer that has there pimped out javascript ready PC at work but they do most of there browsing at home? on there 6 year old PC running windows 95 and IE 4? ( I've no idea what was out then)
Its easy to make this list go on and on.
This makes me think of racial stereotyping, IE. Muslim = terrorist. Obviously a wrong assumption and I realise an extreme example!
People are not binary, logical or anything like that. so you cant assume anything about your user... unless you know what what computers they are using (IE, its internal) - however, even then, at my university i use FireFox from my pen drive and i can have that set-up how i want.
Hmm, I've had enough rambling... I'm going to bed. lol
Good Night.
stolzyboy
03-12-2007, 09:49 AM
some stats for you, courtesy of thecounter.com's global stats as of March 07
Browser Stats
Thu Mar 1 00:01:01 2007 - Mon Mar 12 07:58:01 2007 11.3 Days
Also, I think those stats are inaccurate. Here's an example:
Netscape 1.x 8 (0%)
Well if 8 people use it, how can it be 0% (that is like saying no one uses it). It should be at least a fraction, like 0.2% or something.....
dougal85
03-12-2007, 11:47 PM
What on Earth is "Javascript false"?
I guess it means user doesnt have javascript, like $user->hasJavaScript(); returning false :P I think you may have been trying to be funny but i'm not sure ;) lol
Also, I think those stats are inaccurate. Here's an example:
Netscape 1.x 8 (0%)
Well if 8 people use it, how can it be 0% (that is like saying no one uses it). It should be at least a fraction, like 0.2% or something.....
yeah, basically that's NOONE :) and if those people are found, they are probably dead with their computers on and noone has found them in YEARS :)
leatherback
03-13-2007, 09:07 AM
Hm.. Perhaps I should install that again. I must have a floppy somewhere with it on it. Than I can finally make a difference! :)
piersk
03-13-2007, 09:41 AM
dougal, why did you link to google in those calculations?
dougal85
03-13-2007, 10:09 AM
because i used google as my calculator and i was showing i wasnt just making the numbers up... if you click on them it takes you to the calculation+answer provided by google.
piersk
03-13-2007, 10:37 AM
Ah, ok. Ta
Weedpacket
03-14-2007, 03:43 AM
yeah, basically that's NOONE :) and if those people are found, they are probably dead with their computers on and noone has found them in YEARS :)
If I die I want to be buried with my browser.
stolzyboy
03-14-2007, 09:51 AM
If I die I want to be buried with my browser.
And so it shall be done...
etully
03-14-2007, 11:57 AM
If I die...
If? Wow, that's the most optimistic statement I think I've ever heard.
piersk
03-14-2007, 01:23 PM
Welcome to the world of WP
dougal85
03-14-2007, 02:12 PM
lol, could do with an else statement too :P
EPJS
03-14-2007, 08:40 PM
lol, could do with an else statement too :P
<?php
if (Weedpacket == dies) {
echo "Bury him with his browser";
}
else {
echo "Weedpacket is immortal, he must be a God :eek: ";
}
?>
PHP Builder
Copyright Internet.com Inc. All Rights Reserved.