Skip to page content or skip to Accesskey List.
Search evolt.org
evolt.org login: or register

Work

Main Page Content

Links & JavaScript Living Together in Harmony

Rated 4.49 (Ratings: 47) (Add your rating)

Log in to add a comment
(34 comments so far)

Want more?

 
Picture of Jeff Howden

Jeff Howden

Member info | Full bio

User since: December 13, 1998

Last login: June 22, 2011

Articles written: 21

It seems there's not a week that goes by that someone isn't asking about how to properly execute some JavaScript from a link. Unfortunately, they're not usually driven to bring their problem to others for help because they're trying to make their site as usable and accessible as possible.

So what's the problem?

The most likely problem that brings them away from their troubleshooting session, and to one of the many discussion lists I subscribe to, is the document "jumping" back to the top when a link is clicked. Other times, it's the JavaScript not behaving properly or outright throwing an error.

So what's the solution?

Nearly always there are responses that tell the poster to add return false to the onclick event handler immediately after executing the JavaScript statement(s) or to put the JavaScript statement(s) in the href attribute prepended with the JavaScript: pseudo-protocol rather than use the onclick event handler at all. It's too bad that none of these solutions really addresses the larger problem — how to make the link degrade well for non-JavaScript users.

If we're trying to accommodate non-JavaScript users, why use JavaScript at all?

There are many reasons to execute JavaScript from a link. The most common uses involve navigating to other pages, opening a link in a popup window, or worse, submitting a form. All of these reasons can be addressed while not leaving out non-JavaScript users. Some of the less common reasons usually involve more complicated JavaScript-driven functionality. However, while the functionality can't likely be reproduced for non-JavaScript users, especially in the case of DHTML, the link that's used to trigger this functionality can be used to either execute server-side functionality to mimic or duplicate it or inform non-JavaScript users what they would be getting if they were using a browser with JavaScript support.

So what's really the solution?

The solution is to think about the functionality the JavaScript will provide and how to accomplish the same task without it. Get it working without first, then add JavaScript to enhance it for JavaScript enabled browsers. Let's take a look at some of the common reasons.

What's the most common reason and its solution?

Opening a link in a popup window

Generally developers will open links in a popup one of two ways:

Executing JavaScript from the onclick event handler and setting the href attribute value to "#".
<a
 href="#"
 onclick="window.open('somedoc.html', 'newWindow')"
>click here</a>
Executing JavaScript from the href attribute by way of the JavaScript: pseudo-protocol.
<a
 href="JavaScript:window.open('somedoc.html', 'newWindow')"
>click here</a>
Note
This second example is particularly bad because it causes the link to break for users that prefer to shift+click the link to open it in a new window, unless they're paying close attention to the address in the status bar and notice it's executing a JavaScript statement.

Before charging off thinking either of these ways is the solution, give the code above a try in your browser with JavaScript disabled. You'll notice the first example will cause your browser to jump back to the top of the document if you had to scroll at all to see the link and the second example does absolutely nothing. So, let's talk about how we're going to make this work for non-JavaScript users as well.

Just how do you open a new window for non-JavaScript users?

The beginnings of accessible popup windows is in the use of the target attribute of the &lt;a&gt; tag. We finish it off for non-JavaScript users by placing the link where it belongs — in the href attribute.

<a
 href="somedoc.html"
 target="newWindow"
>click here</a>
But what about the fancy popup for JavaScript enabled users?

To have the browser open a popup window, based on our own settings, we place the necessary JavaScript into the onclick event handler. In addition to this bit of JavaScript, we make sure to add a return false statement as the last bit to keep the browser from executing the default behavior of a link with a target -- opening a normal browser window. We eliminate the need to code the link to the document and the new window name twice by using the this keyword which makes a reference to the containing object, in this case the &lt;a&gt; tag. Using the this keyword and object.property notation, we can access the href attribute value and the target attribute value.

<a
 href="somedoc.html"
 target="newWindow"
 onclick="window.open(this.href, this.target); return false"
>click here</a>
Congratulations! You've made your first completely accessible popup window.

So what are some solutions to other common reasons for executing JavaScript in a link?

If you're trying to submit a form from a link, stop, go directly to jail, do not collect $200.00. Besides the numerous expected behaviors of forms that you're breaking (we're talking about usability here) by not using a submit button of some variety, you're needlessly neutering the form for non-JavaScript enabled users. In the years I've been playing this web game, I've yet to run across a valid reason for breaking a form in this fashion.

If the reason you're looking to use a link is so you have a graphical submit button, stop, go read the html spec, do not collect $200.00 — hello, this functionality is already built-in via the &lt;input&gt; tag with a value of image for the type attribute. If you're stuck implementing someone else's design and they insist upon rollovers on the submit buttons, there are better alternatives that don't break the form for non-JavaScript users.

What's an example of one of the less common reasons and a possible solution?

Suppose you have an application that lists a number of events. These events can be in any number of categories. Using DHTML, you want to give users with capable browsers the ability to see what events belong to which categories, on the fly, without reloading the page. What do you do about non-JavaScript browsers so they get the same end result, albeit with a reload of the page?

We start by building the application without the DHTML. We pass the information about the category the user clicked on to the application so it knows what dates on the calendar and what events in the listings below to "highlight" — this is the simpler part.

We then write a JavaScript function to change the background and foreground colors of the dates in the calendar and the individual events in the listings and change the color of the link the user clicked on to indicate which one is "selected". We call this function from the category links using the onclick event handler. Since this example uses JavaScript that not all Javascript-capable browsers understand, we make sure the function call is prefaced by the return statement. We also make sure the function returns a boolean value of true if the browser does not support the method(s) we're using so it will follow the link just like non-JavaScript capable browsers or otherwise a boolean value of false so the DHTML can be executed without the browser following the link.

The function

function selectEvents(category_id)
{
  if(!document.getElementById) return true;
  // DHTML bits go here
  return false;
}

Calling the function

<a
 href="/calendar/february/2002/6/1"
 onclick="return selectEvents(1)"
>Snowboarding</a>

So what do I do if it's not possible to replicate the functionality server-side?

If for some reason you can't replicate the functionality with some server-side shenanigans, then simply use the href attribute to link to a document that will explain what could be gained by using a JavaScript enabled browser. To execute the JavaScript, use the onclick event handler, remembering to add the return false statement at the very end to prevent JavaScript enabled browsers from following the link. You might also consider using the onmouseover and onmouseout event handlers to write to the status bar to mask the link to the document for non-JavaScript users to prevent confusion on the part of the JavaScript enabled user should they look at the status bar when mousing over the link. If the functionality your JavaScript statements provide is not compatible with all JavaScript enabled browsers then you may consider prefacing the function call with the return statement as in the example immediately above.

Executing JavaScript that is compatible with all JavaScript enabled browsers

<a
 href="js_required.html"
 onmouseover="window.status = 'click here'; return true;"
 onmouseout="window.status = '';"
 onclick="myFunction(); return false;"
>click here</a>

Executing JavaScript that is not compatible with all JavaScript enabled browsers

<a
 href="js_required.html"
 onmouseover="window.status = 'click here'; return true;"
 onmouseout="window.status = '';"
 onclick="return myFunction()"
>click here</a>

In conclusion

I haven't covered all the possibilities or reasons for calling JavaScript within links. However, I hope you've seen that there are ways to do so and have the page degrade as gracefully as possible. If I haven't touched upon something you've struggled with, I hope I've given enough inspiration and guidance to encourage you to find the most usable and accessible solution possible. Links and JavaScript really can live together in harmony.

.jeff

Jeff Howden (.jeff) is a web developer working for Vos & Howden, LLC in Portland, Oregon where he's partnered with long-time colleague, Anthony Vos. His skills include ColdFusion, JavaScript, CSS, XML, relational databases, and much, much more. His biggest professional accomplishments include, but are not limited to:

  • building a ColdFusion-based e-commerce solution for Mt. Bachelor that transacted over $1.62 million dollars in September 2001 with 0 (yes, that's zero) ColdFusion errors and then an almost completely rebuilt version transacted $2.86 million dollars in September 2002.
  • being asked to be a Technical Editor for the ColdFusion MX book, Inside ColdFusion MX from New Rider's Publishing company.
  • being asked by BrainBench to perform quality control on their JavaScript 1.5 certification test after receiving the highest beta test score out of 200 testees.
  • managing the server that hosts evolt.org and withstanding a slashdotting that brought over 1,000,000 hits to the site, over 10 gigs of data transfer, and an average in excess of 2300 unique visitor sessions per hour, all within a 24-hour period and the server never hiccuping once.

another frequent question answered!

Submitted by r937 on February 6, 2002 - 15:20.

thanks jeff!! this is the article i've been wanting to write for months, and you've saved me the trouble (see? procrastination does pay off!)

actually, you went a lot further than i would have -- nice job, and nice examples

and now i've got an article link for the Because your page doesn't have an "#" anchor answer on my Frequent Questions Answered page <grin />

login or register to post comments

Fantastic

Submitted by gnarly on February 6, 2002 - 17:15.

I was just about to ask the "whats the best way to do a JS link" question on thelist. Cheers for this, I'll be bookmarking it!

login or register to post comments

guilty as charged

Submitted by fabricari on February 6, 2002 - 19:12.

As I am guilty of creating many inaccessable pages, it's good to see a better solution. Thanks.

login or register to post comments

thank you

Submitted by lau on February 6, 2002 - 19:40.

great article. Some very clever thinking there.

login or register to post comments

More info ?

Submitted by Mishka on February 6, 2002 - 20:08.

Hey Jeff,

Yes, nice article .. one I'm sure many of us will refer to and link to over time. Care to add a bit of info on how to go about resizing the new opened window, get rid of scroll bars, get rid of nav bars, etc. Not that those are necessarily a great thing to do, but they are common. Just a suggestion of course. I've only forced open a new window at a specific size on Admin areas of some of my sites .. to be used as "help" screens.

Mich

login or register to post comments

Re: More info ?

Submitted by Jeff Howden on February 6, 2002 - 20:34.

Michele,

I don't think I want to go in to more detail about how to control windows, validate form data, perform specific DHTML functionality, etc. as the specifics of these things are outside the subject of this article — using JavaScript responsibly.

Thanks for the compliment on the article though. I know that I'll personally be linking to it alot instead of restating my case each time someone asks questions about this.

.jeff

login or register to post comments

One tiny problem

Submitted by carlitos on February 7, 2002 - 15:49.

Great article.... encore, encore!

However, there is one tiny problem with one of the solutions/workaround you posted:

"If the reason you're looking to use a link is so you have a graphical submit button, stop, go read the html spec, do not collect $200.00 — hello, this functionality is already built-in via the input tag with a value of image for the type attribute."

"input type=image" is not a valid javascript object type and calling a function on onClick will not work on netscape 4.xx.

Cheers

login or register to post comments

Re: One tiny problem

Submitted by Jeff Howden on February 7, 2002 - 16:30.

Carlitos,

"'input type=image' is not a valid javascript object type and calling a function on onClick will not work on netscape 4.xx."

That's correct — NN4 does not support an onclick event handler on an image submit. Don't let that keep you from using it though. Many times, the functions you'd call from the onclick event handler can be moved to the onsubmit event handler of the &lt;form&gt; tag without any adverse affects. The only time it causes problems is when you're using multiple image submits and the action the form performs is different based on which image the user clicked on. Since this is usually avoidable client-side, it's not really an issue. After all, you've got to account server-side for the user that doesn't have JavaScript enabled at all, right?

Additionally, it could be argued that more than one image submit could be confusing to the user and should therefore be avoided anyway, completing removing the need to have an onclick event handler on the button.

However, that doesn't mean you have to let that stop you, if you really need this functionality. Simply adapt the script I wrote to facilitate image submit rollovers to your needs. Remember, you can always develop your form to use a basic submit button in the html and then replace it programmatically with something else for those users that support JavaScript at the level you need.

Thanks,

.jeff

login or register to post comments

Re: One tiny problem

Submitted by mwarden on February 7, 2002 - 21:11.

.jeff wrote:
Many times, the functions you'd call from the onclick event handler can be moved to the onsubmit event handler of the <form> tag without any adverse affects.

I'd go a step further and say that 99% of the time, the function in the onclick would more appropriately be placed in the onsubmit handler of the form. Most of the time, you'll benefit from doing so (ever submit a form by hitting 'Enter' or by some method other than clicking the button?).

login or register to post comments

Thanks

Submitted by SleepwalkR on February 10, 2002 - 10:29.

This definately is a great tip. Thanks a lot!

login or register to post comments

The right article at the right time

Submitted by twigletmac on February 11, 2002 - 02:15.

The day this article was published I was about to start converting part of our old static HTML site to our new (with bells and whistles and everything) dynamic PHP site. I'd been handed a section that contained some gimmicky Javascript pop-ups and having failed to convince the original creator to scrap them I offered (using this article as a guide) to make them accessible. It worked brilliantly and now it doesn't matter whether you're using Javascript or not you get all the info. Thank you for a really useful article.

login or register to post comments

Devilish suggestion!

Submitted by ben_h on February 19, 2002 - 19:37.

(Ben recognizes he will be stoned for saying this, so runs, and looking back, shouts) -- Guys, forget all this jazz and just simply use Flash! It works in almost every browser on the planet worth showing something on, and looks EXACTLY the same without all these frantic coding rigmaroles.

login or register to post comments

Re: Devilish suggestion!

Submitted by Jeff Howden on February 19, 2002 - 20:18.

Ben,

Are you kidding? You're posting a comment suggesting Flash is a solution to an article that's pushing for accessibility. :Þ

Accessibility isn't something that's been one of Flash's strengths. In fact, since accessibility has become more important to the everyday developer/designer, Macromedia has felt the pain in their side regarding Flash's complete lack in that department. That will all change with the new version I've been told, but that won't be a factor until the adoption percentage is quite high.

Another problem with Flash in its current incarnation is it's not really a UI based paradigm. It's much more geared towards the movie paradigm -- frame after frame after frame. For example, all the work necessary to implement a form in Flash and the usual accessibility bits a browser includes by default would be a serious undertaking. Consequently, alot of the forms designed in flash don't support tabbing between fields, don't support accesskeys, tabindex, etc. — at least not in some of the ones I've encountered.

How can Flash help in the creation of a dropdown or fly-out menus? What is involved in layering a Flash movie over other content? To do this aren't you suddenly dancing with the devil of DHTML again? "No!", you say. "You can just make the Flash movie taller/wider and keep the menus within it", you continue. So, to use Flash I must compromise the placement of my content and add unnecessary whitespace to my design and push my content further below the fold on an already obscenely cramped display area? Sign in blood on the dotted line partner, you're not getting out of the need for JavaScript/DHTML that easy.

There are also other issues with Flash. How do you effectively offer Flash to only those that have it? Answer -- use JavaScript/VBScript to detect or use a tiny Flash movie to perform a redirect. This "works" (if you don't have issues with redirects) for splash pages, but seriously sucks (i.e., is totally unacceptable) when trying to use Flash for things like navigational elements. Making an argument that practically every user has Flash installed is naive and pathetically assumptive. Many users may have it installed but have their browser set to prompt them before running any ActiveX controls on the page (yours truly included). So, I have it installed but choose to not use it cause I usually hate the implementation and am too lazy to uninstall it (or am required to have it for work).

You mention "frantic coding rigmaroles" involved and suggest Flash as a solution. To me, I see trying to mold Flash in to a possible solution the equivalent of "rigmarole". Finally, if the issues I've mentioned in this article are taken into account when the functionality of the site is being conceptualized, the franticness can be avoided and clear steps to developing solutions that don't compromise non-JavaScript users can be implemented successfully.

In the instances where the user doesn't support or activate Flash on a given page, how do you provide similar funcationality for them? Take my calendar example noted in the article? How could Flash effectively be used to accomplish the same results I came up with using server-side code and some careful use of JavaScript? I personally don't see it happening in such a way that it will support non-JavaScript and/or non-Flash users without there being quite a bit more work.

Good luck,

.jeff

login or register to post comments

wow..

Submitted by shanx24 on February 19, 2002 - 21:08.

jeff, i dread to step into a debate with you, but assuming that this is a self-educational and honestly friendly discussion, i will give myself a free reign.

first of all, what flash is used for NOW has nothing to do with what it CAN be used for, including flash 5 (let alone the jazzy gaga we hear about upcoming flash 6). flash 5 is primarily used right now by either immature designers or mature-but-primarily-care-for-cool-look designer-turned-programmers, which explains all those anti-aliaced fonts and nervously eventful movies -- which, for the record, i don't much care about either. but let me address your points in a more organized manner:

1. flash adoption rates are 96% (its a statictic, give or take a few centage points). this is not only from macromedia but third party sources as well. check up nua.com or other some such place. an inhouse group in the company i work for had some great stats on this. of course, a lot of this users *possibly* disable the plugins and activex but we are talking of moving on with technology.

2. the kind of accessbility and usability, and navigation that can be provided with flash is mind-boggling and only limited by the imagination. take a look at www.bornmag.com for a sample of navigation that i simply adore. on top of the page, i type the name of an author, and it short-lists the available authors pronto. i know i can achieve this with JS these days with data binding, but heck how many browsers will i test (not to mention the speed of JS execution in reality).

3. as for flyout menus and drop downs - come on, you arent serious are you? flash can kick dhtml's butt anytime in that department. i am literally overflowing with examples to show you, but to begin with, pls take a look at www.carbonhouse.com or www.becominghuman.org for instance. this should address your point of layering menus. (i am not sure if these are best examples, just the ones on top of my mind right now but the navigation of the whole website is amazing). on the JS side, look at how much effort is spent by webreference folks in making their "heirarchical menus" (now in version 4.xx i think) to make it work consistently across browsers.

4. i am sure you know this already, but since your post seems to suggest otherwise, i will smoosh this in: flash supports xml (although primitive + slow right now) and text parsing, and can be used with almost any server side language (JSP/PHP/ASP/CGI ...you name it) because flash is a client-side solution. javascript and dhtml are also client side. you send data from the server and your client handles it. JS is quickly getting outdated and is slower than flash, is less prettier (its gonna matter sooner or later when we compare, imho) and is definitely more cumbersome to manage with all this cross platform coding "rigmarole" as ben termed it. there is a good reason why java (despite being a slow beast) is doing so well: it is cross platform so i code ONCE and deploy. similar with flash if your client is a web browser (where java fails miserably with its applets although take a look at some great use of applets at www.smartmoney.com.

5. form handling (tabbing etc).... point very well noted! i too have to see movies where people care about real forms. however, once a flash coder gets serious, all this can be achieved pretty easily with existing flash, including some pretty fancy clientside content validations. piece of cake. (btw, i also hate when programmers create their own navigational spaces in flash where i need to click on THEIR scrollbar to read text instead of my usual mouse wheel...but again, can be addressed pretty easily). in general though, your idea of flash not being a GUI based tool is very well noted, and i think that does tend to be a weakness of flash but (a) this is subjective (b) can be easily implemented using and (c) may be a small price to pay for all the benefits of flash.

benefits you ask? here are some of the more important ones:

1. cross platform - code once, and sleep well
2. my coding effort remains secure and safe (good for commerce) because you cannot, hey, like ViewSource and plagiarise that easily
3. user experience can be fantastic, in fact, kicks butt of all other technologies
4. content can be dynamic as well, and hey, it can be NOT anti-aliased (and imagy looking) as well if i want so that it looks like "usual" content

the only current caveats with flash that i can think of are that some folks may turn it off as you pointed - because, again, it has been so damn abused by those splash and "intro page" creators with loud music and needlessly flying text/images that steals from the credence of flash (and its real capability). but once we have some "serious" websites which use flash for more than just display -- including the big brand names and some examples that i can dig up if you wish -- then i am sure this is quite likely to change. people just need simplicity, and flash can offer that when in the right hands.

secondly, flash has historically emerged from the domain of designers so there is a good likelihood that the "IT guys" will blow over it and never really take it seriously ("oh that frilly design tool?"). i am personally more on the IT side of the fence than the creative, but i may be among the few who see a lot of potential in flash if it is used sensibly. (or maybe i am just plain astray).

again, your article is great and most definitely very very useful to a lot of people. but i would tend to agree with ben_h that flash will make its significance felt pretty soon. and for very good reason, imho.

apologies for the long rant! would *love* to hear your thoughts.

shashank tripathi
tokyo | www.shanx.com

login or register to post comments

Accessibility Must Come First

Submitted by OKolzig37 on February 20, 2002 - 15:33.

The problem is that Flash's idea of accessibility is to invest development time into having a second version of the site that is accessible. So, this leaves you with two options:

  1. Ignore accessibility concerns, violate the various laws, rules and regulations and alienate some of your user base just so things can "move around and look pretty" despite the fact that there are accessible equivalents to that technology...or...
  2. Create a second version of the same site that does not use inaccessible technology and have the assorted maintenance and upkeep required to keep two versions of the same site going (even if they are pulling from the same data).

The word "accessibility" has that one root word in it: "access." The goal is to give that access to everybody. It's not just a good idea, it's the law.

login or register to post comments

Re: wow..

Submitted by Jeff Howden on February 20, 2002 - 20:28.

Shashank,

I'll warn you now. If you're not interested in reading an epic of a response then move on. However, while I tried to keep it as short as possible, I feel there is alot of valuable insight in this response that couldn't be left out. I'll leave it as an exercise for you, the reader, to determine if my opinions have validity.

jeff, i dread to step into a debate with you, but assuming that this is a self-educational and honestly friendly discussion, i will give myself a free reign.

You needn't fear debate with me — unless you can't put together a reasoned argument with solid facts to back them up. You've done a good job of that, though I think you've missed some key points of my argument and have therefore sort of missed the boat on disproving my take on the situation.

first of all, what flash is used for NOW has nothing to do with what it CAN be used for, [...]

Agreed. Obviously what it can be used for comes at too high a price (development time), otherwise we'd see more examples of accessible Flash implementations. Either that or the average Flash developer/designer doesn't give a rat's ass about accessibility, which is too often the case as well.

1. flash adoption rates are 96% [...]

No offense, but I don't buy into these statistics as the methods for arriving at them are skewed and innacurate to begin with. That's really not the basis for my argument though. My point is what are you going to do for those users without Flash, have Flash disabled, or are using older versions of Flash that don't support things that require the latest version. Are those without Flash or who choose to disable it stuck with a rectangle where the Flash should be but no usable mechanism to get at the functionality or content the Flash interface provides? If I develop the functionality with JavaScript and a mix of server-side compensation, I can make sure that it's accessible and usable by everyone with the only disadvantage to non-Javascript users being a trip to the server for each click. Can you make the same claims with a Flash implementation? If so, how does the amount of work involved compare?

2. the kind of accessbility and usability, and navigation that can be provided with flash is mind-boggling and only limited by the imagination. take a look at www.bornmag.com for a sample of navigation that i simply adore. on top of the page, i type the name of an author, and it short-lists the available authors pronto. i know i can achieve this with JS these days with data binding, but heck how many browsers will i test (not to mention the speed of JS execution in reality).

I agree that the filtering mechanism is really slick. However, there are a number of elements about the design that are quite flawed. For example, try using the site with only the keyboard. You'll notice that the tab order is very messed up. You'll also notice that the feedback to the user when they eventually tab the focus to the links in the site is very muted and not at all consistent with what the keyboard surfer is likely to expect. In addition, the tab order seems to completely miss some of the elements in the Flash movie making them completely inaccessible. That suggests to me that creating the ability to tab between elements is not as easy as it looks.

Now, to make yourself really frustrate. Open up some screen reading software, turn off the monitor, and see if you can find the information you're looking for on the site. I guarantee you can't.

Furthermore, if I'm a non-Flash user, how am I to get at the same information? Is it simply not available to me because the interface to the content hasn't been developed? That seems ridiculously exclusionary to me. I suspect proponents of Section 508 of the Workforce Investment Act of 1998 are likely to take issue with that approach.

3. as for flyout menus and drop downs - come on, you arent serious are you? [...]

Yes, I'm absolutely serious.

flash can kick dhtml's butt anytime in that department. i am literally overflowing with examples to show you, but to begin with, pls take a look at www.carbonhouse.com or www.becominghuman.org for instance.

None of the sites I've seen that use dropdown or fly-out menus address the issue I brought up. The issue I brought up is where Flash is only used as the navigational portion and the rest is done with HTML and the Flash has to render dropdown or fly-out menus outside the rectangle of the Flash file and overtop the HTML elements. They usually get around that issue one of two ways:

  1. Create the entire site in Flash.
  2. Increase the height or width of the design to give room to perform the dropdown or fly-out menu within the rectangle of the Flash file.

Both of these solutions have their own set of problems, however. The problems with the first solution I've expanded on above. There are also problems with maintaining two entirely different sites (even if the content is dynamic and database-driven) should the design needs change. The problems brought on by the second solution involve cluttering the design with odd-looking whitespace or gratuitous design elements within the Flash file to cover for the extra space added, unnecessarily reducing the amount of minimal horizontal width for the HTML content, in the case of a vertical navigation implemented in Flash, or pushing the HTML content too far down the screen, often below the fold, for a horizontal navigation implemented in Flash.

on the JS side, look at how much effort is spent by webreference folks in making their "heirarchical menus" (now in version 4.xx i think) to make it work consistently across browsers.

The effort spent by the WebReference folks on heirMenus is completely unnecessary unless you have the ridiculous notion that you should provide support to all DHTML-capable (term used very loosely so as to include NN4) browsers. However, if the majority of your audience is using DOM-compliant browsers (IE5+ Win/Mac, NN6 Win/Mac/Unix, etc.), then your work is significantly less as the cost/benefit analysis doesn't weigh out in favor of trying to provide the minority with the extra functionality and eaase of use often afforded by dropdown or fly-out menus.

4. i am sure you know this already, but since your post seems to suggest otherwise, i will smoosh this in: flash supports xml (although primitive + slow right now) and text parsing, and can be used with almost any server side language (JSP/PHP/ASP/CGI ...you name it) because flash is a client-side solution.

Yes, I'm fully aware of the ability to push/pull external content into a Flash file and process it programmatically. We're actually using that functionality within an application for a client. However, that ability doesn't really address the issues of accessibility I'm bringing up though. It also doesn't address how you design the site to handle those non-Flash users.

JS is quickly getting outdated and is slower than flash, is less prettier (its gonna matter sooner or later when we compare, imho) and is definitely more cumbersome to manage with all this cross platform coding "rigmarole" as ben termed it.

JavaScript is getting outdated? Maybe you should tell that to the folks that are constantly working on improvements and extensions to it. No offense to you personally, but anybody that thinks JavaScript is on the way out is smoking some wacky crack.

It's getting slower? I don't know that I buy into that notion. If anything it's getting faster and more powerful. What's more, as users upgrade to faster machines, the execution time for client-side scripting will only improve.

The cross platform "rigmarole" is only necessary if you're looking to do a complicated task and have it supported by as many capable browsers as possible. This isn't really necessary in many cases though. For example, if your logs indicate that less than 10% of the visitors to your site use NN4, why spend obscene amounts of time developing/debugging the solution so it works client-side for them and therefore bloating the code for the majority of your audience who won't benefit from it? Not only are you guaranteeing it will run slower for most of your users, but you're also increasing the download time for your users and pushing up your bandwidth costs. It doesn't make any sense. Simply take those users in to account when developing the server-side portion of the solution. Suddenly your problem of support is solved and the majority of the users get the speed benefits of not having to make a trip to the server to perform a given task, while the rest can still get at the content. When in doubt, go lean. Supporting the majority with the absolute minimum translates into profitability.

5. form handling (tabbing etc).... point very well noted! i too have to see movies where people care about real forms. however, once a flash coder gets serious, all this can be achieved pretty easily with existing flash, including some pretty fancy clientside content validations.

This sort of stuff is absolutely ridiculous to do in Flash. Not only does it require quite a bit more work on the Flash designer's part to build in all the standard form behavior that's just naturally a part of the browser, but it doesn't really accomplish anything that couldn't be done with JavaScript. Ok, so you can style your &lt;select&gt; elements, radio buttons and checkboxes better in Flash, but some would argue that you shouldn't be messing with the look and feel of these elements either. Validation is a non-issue as I challenge you to find any bit of data validation you can perform in Flash that I can't either perform client-side for those clients that support it or server-side for the rest.

(btw, i also hate when programmers create their own navigational spaces in flash where i need to click on THEIR scrollbar to read text instead of my usual mouse wheel...but again, can be addressed pretty easily).

That's another one of my pet peeves with Flash. If I encounter a scrollable element, my mouse wheel better work there. It bothers me to have to move my mouse to the scroll controls and figure out how the developer implemented them — hopefully in a fashion that exactly mimics how normal scroll bars work. All too often they work completely differently or only support the most basic of actions. For example, some of the worst implementations involve hovering your mouse over an up/down arrow to cause the window to scroll. There's no way to control how slow/fast the scrolling happens. Other implementations require that you click on up or down arrows and even display the bar between the arrow buttons to indicate where in the document you are, but don't allow you to click between the bar and an arrow to jump a page in the desired direction or drag the bar to manually scroll the document the desired amount. The UI elements are there, but they don't work.

1. cross platform - code once, and sleep well

This is only true if you can guarantee that all clients that will be viewing your Flash file are running the same version. If you're relying on functionality provided by Flash 5 and a user is trying to view it with Flash 4, they're going to run into problems. It's really no different than coding for v5+ browsers and having a user view it in a v4 or below browser. If you don't account for that possibility and build it to fail gracefully, you haven't done your job.

2. my coding effort remains secure and safe (good for commerce) because you cannot, hey, like ViewSource and plagiarise that easily

If you're relying on the nuts of bolts of a particular piece of functionality to be secure, then you should be doing it on the server to begin with where it can't be messed with at all.

3. user experience can be fantastic, in fact, kicks butt of all other technologies

I heartily disagree. If you're talking about the graphical representation, floating and morphing things being awesome, that's true. But, that's not what user experience is all about. User experience is about the piece the user is interacting with behaving in a fashion they'd expect. I have yet to encounter a Flash-based application that accomplishes this with any measure of success. To quote Apple, from the link above:

"User Experience is a broad term describing the visual appearance, interaction and feedback, and assistive capabilities of software. ... People who use Macintosh computers want all their applications-whether they're spreadsheets, word-processors, Email and Internet browsers, accounting products, or design tools-to have the consistency, intuitive design, and ease of use that's characteristic of Macintosh software."

The above could very easily be applied to browsers and web sites. For a user, things should behave as they expect or are accustomed to. If the user is used to right-clicking a text-field to paste some text from their clipboard, the replacement interface had better support it since the browser does. If I'm accustomed to saving time with the auto-complete feature in IE5+, then I'm going to be bothered using your alternate interface as I will have to manually enter each piece of data. If you have a dropdown menu, it had better select the third option that begins with the letter "O" if I give it focus and press the letter "O" on my keyboard three times. Checkbox elements should be square. Radio buttons should be round. Any other shape and I won't recognize the element and its intended behavior. These are all things users have grown accustomed to in their browser of choice and if you can't duplicate (impossible with some things) them in functionality and behavior entirely, then don't waste anyone's time.

the only current caveats with flash that i can think of are that some folks may turn it off as you pointed - because, again, it has been so damn abused [...]

Unfortunately the abuse is only going to get worse. We're starting to see a marked increase in the number of banner ads that are implemented with Flash. For this reason alone I think you'll find more and more people disable or uninstall it.

but once we have some "serious" websites which use flash for more than just display -- including the big brand names and some examples that i can dig up if you wish -- then i am sure this is quite likely to change. people just need simplicity, and flash can offer that when in the right hands.

I don't doubt that it can. My problem is that doing so means creating two completely separate sites, one in Flash and one in HTML, to account for those users who simply don't have and/or won't get Flash. This creates unnaturally high costs for the development and maintence of the site. Most clients won't buy into these costs and will opt (thank god) to not build the Flash version. Those that do will usually abandon the Flash version when it comes time to do a redesign. For those clients whom cost is no barrier, they'll create the two versions, but completely miss the point when developing the HTML version. Take Tiffany.com is a great example. Try their service page. If you're using IE5+, use this bookmarklet to view the actual text on the page. Don't be surprised when all you see is an empty alert() dialog.

The notion behind their HTML version is completely flawed. It's not even taking into account the mitigating factors for this version's average user. Users who don't have Flash aren't likely to be on a high-speed connection or are visually impaired, yet the HTML version is bloated with pages made up almost entirely of gif-text. Who's been helped by this? Blind users aren't. Users on 28.8 or 56k aren't. I can't even begin to imagine the maintenance costs associated with updating a site like that.

again, your article is great and most definitely very very useful to a lot of people. but i would tend to agree with ben_h that flash will make its significance felt pretty soon. and for very good reason, imho.

Whether or not it finally gets around to flexing it's muscles in the UI arena remains to be seen. To many people it's still just a way of putting together bandwidth-conscious animations and sound clips. Maybe one day it will become known for something more than that. For me and many others I suspect, it's not a viable solution to most of the problems encountered by the average web developer struggling with cross-platform/cross-browser madness. It may eventually help alleviate that, but will probably always beg the $64,000 question — "How can I account for those users who can't/won't use Flash?"

Thanks,

.jeff

login or register to post comments

Wow

Submitted by OKolzig37 on February 20, 2002 - 20:42.

Great post, Jeff. Accessibility is forgotten about all too often during development simply for the sake of doing the latest and greatest. I'd have to keep this article bookmarked just for that. Thanks!

--Ben

login or register to post comments

Point of clarification...

Submitted by carlitos on February 27, 2002 - 09:30.

Hey Jeff,

Just one tiny question. Could you provide more detail regarding the differences between the following code:

onclick="return myFunction();" and onclick="myFunction; return false;"

Why would the first example have a higher chance of working out? What is actually happening as a result of the syntaxt difference?

Many thanks,

Carlos

login or register to post comments

Re: Point of clarification...

Submitted by Jeff Howden on February 27, 2002 - 19:39.

Carlitos,

Just one tiny question. Could you provide more detail regarding the differences between the following code:
onclick="return myFunction();" and onclick="myFunction; return false;"
Why would the first example have a higher chance of working out? What is actually happening as a result of the syntaxt difference?

Each syntax has a specialized use. Use the former (onclick=&quot;return myFunction()&quot;) when you need to be able to conditionally allow the JavaScript-enabled user to follow the link. Use the latter (onclick=&quot;myFunction(); return false;&quot;) when you always want to have the JavaScript-enabled user execute only the onclick event and not follow the link.

.jeff

login or register to post comments

New window target

Submitted by bobince on March 10, 2002 - 15:53.

Good article! I've been shouting at people posting examples with javascript:-link popups for what seems like half my life, it'll be handy to have this URL at my fingertips...

On a minor point: for a new-every-time popup window, _blank is a better value for target than a name like newWindow; otherwise one can navigate away in the new window only to have its contents replaced when clicking on another link with the same target name. Really confusing if you're browsing with multiple windows.

Oh, and can you change the last example? I wouldn't want to encourage anyone to use the awful window.status-changing-trick!

(Me, I can't understand the "Flash will replace HTML!" sentiment I see so often. To go back to a presentation-centred proprietary binary format seems to miss the entire point of the web. It's great for animation content and games and stuff, but building navigation and textual content with it just seems perverse. But that's a different flame war, so forget all that.)

login or register to post comments

Flash Adoption Stats

Submitted by cothrun on July 28, 2002 - 16:06.

Its a little late for this conversation but I enjoyed the article and the debate regarding Flash.

I wanted to add one tidbit of information to the debate regarding Flash. The adoption percentages mentioned are at best for the Flash player version 4. Flash 5 (IMO, the first truly useable version for 'applications') is at 90%. Flash 6 is currently approaching 40% but that one will continue to rise quickly over the next year or so.

10% (missing Flash 5) is too much to give up for a general purpose site. For a controlled environment(I'm working on a HTML/Flash kiosk system), for a specific audience or with no other way to present the content, it might be worthwhile to give up and take advantage of Flash.

Macromedia's Flash Adoption Statistics breakdown.

login or register to post comments

javascript links and search engines

Submitted by minivip on March 26, 2003 - 14:57.

Interesting article, but I am irritated why there is no hint about javascript links and problems with search engines. As search engine spiders are not able to run javascript it's important to use links that are accessible for non javascript clients. Otherwise it may happen that nobody will visit your pages, as nobody finds them in the engines.

login or register to post comments

Re: javascript links and search engines

Submitted by Jeff Howden on March 26, 2003 - 15:04.

Gerald,

You make a very valid point. I know I don't come right out and say "Search Engines" in my article, but would definitely say they fall into the "non-JavaScript users" category.

Thanks,

.jeff

login or register to post comments

Links for submitting forms

Submitted by douglerner on April 19, 2003 - 18:20.

You mention that you have not encountered a reason for using links to submit forms. But I am trying to do this now for two very good reasons: (1) I have a form with a bunch of control buttons and it looks just awful. I would like to consoildate everything into something that looks smart and organized and takes up less screen space AND (2) The site is multi-lingual. The UI language depends on the user preferences. Doing this with localizable text strings - not images - is the only reasonable approach. Just a thought. doug

login or register to post comments

Re: Links for submitting forms

Submitted by Jeff Howden on April 19, 2003 - 18:38.

Doug,

(1) I have a form with a bunch of control buttons and it looks just awful. I would like to consoildate everything into something that looks smart and organized and takes up less screen space [...]

Switching to text links to instead of buttons is a seriously bad move. Not only are they no longer visually connected to the form, they're completely useless to non-javascript enabled users (to bring it back to this article). I'm sure alittle massaging with some CSS and you'd have some nice looking buttons (that still look like they belong to the form) that don't take up a ton of room.

Without actually seeing the form you're talking about it's difficult to say for sure, but I bet the form you're working with just needs some simplification. It's probably more a case of trying to pack too much into the same space when it really should be shared across several different forms. It's been a very long time since I've developed a form that needed more than 3 buttons. Maybe it's time to see if you can bring the number of buttons down to a reasonable number.

(2) The site is multi-lingual. The UI language depends on the user preferences. Doing this with localizable text strings - not images - is the only reasonable approach.

I absolutely agree. However, I just don't see how that equates to using text links for form submission. Input buttons take text string values just as well as links do.

I still have yet to encounter a situation where it's necessary to use text links instead of buttons. Your situation certainly doesn't warrant it.

.jeff

login or register to post comments

OK..

Submitted by Putte_5 on May 23, 2003 - 04:20.

I tend to agree with you there.

login or register to post comments

Calling Javascript from QTVR?

Submitted by eddaniel on July 10, 2003 - 14:51.

Hi, great article. Nice to see how it's done properly :)

I've got a bit of a problem, namely trying to call a javascript function from a QTVR hotspot link in an accessible manner. You can link to anything that you can put into an href, including "javascript:". At the moment I'm using this simply to alert("This destination isn't ready yet") where I haven't made the neighbouring QTVR yet, so if it breaks it isn't critical (although not ideal).

However, I'm redoing the layout, and want to use one iframe to contain the QTVR and another to contain descriptive text. Assuming QuickTime, iframes and Javascript are available, clicking a QTVR link should call a function to update the 2 iframes. If the user's setup doesn't support iframes and/or JavaScript, the fallback will be to reload the entire page with the new information. This is fine, until we have someone with iframes and JavaScript, but whose browser doesn't like a href="javascript:doSomething()". Then absolutely nothing happens, and the user is stuck.

It appears that I can't add "onClick" attributes to the QTVR hotspot links. Any idea how I can either duplicate the functionality of onClick, or test for support of "javascript:" type calls over and above JavaScript support?

Here's a typical block of code I'm using to include QTVRs on my pages:

<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="192" height="128" codebase="http://www.apple.com/qtactivex/qtplugin.cab">
<param name="src" value="http://localhost/qtvr/3day.mov" />
<param name="controller" value="false" />
<param name="cache" value="true" />
<param name="scale" value="tofit" />
<param name="hotspot1" value="http://localhost/main.php?world=city&point=2&lang=en&qt=yes" />
<param name="hotspot3" value="http://localhost/main.php?world=city&point=4&lang=en&qt=yes" />
<param name="hotspot5" value="javascript:alert('This destination isn\'t ready yet')" />

<embed height="128" width="192" controller="false" pluginspage="http://www.apple.com/quicktime/download" src="http://localhost/vrjourney/city/qtvr/3day.mov" scale="tofit" cache="true" hotspot1="http://localhost/vrjourney/main.php?world=city&point=2&lang=en&qt=yes" hotspot3="http://localhost/vrjourney/main.php?world=city&point=4&lang=en&qt=yes" 
hotspot5="javascript:alert('This destination isn\'t ready yet')">
</embed>

</object>

It's a nasty, quite specific problem, and several hours of Googling have failed to turn up an answer, so many thanks for any pointers you can give.

login or register to post comments

Great article

Submitted by henrik_m on November 17, 2003 - 09:06.

Thanks, this one is very much appreciated.

login or register to post comments

SEO and Flash

Submitted by rHBa on June 4, 2006 - 06:55.

Another example of in-accessible Flash is with SEO, the content will be invisible to search engine robots, they say in SEO circles that 90% of the content on Flash sites is 'Skip Intro'. Having said that, I here that if your movie is XML fed you can do a robot friendly serverside redirect to the XML data and get ranked but if your time/budget doesn't stretch to that then stick to an accessible format (HTML).

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GAT/! d-(pu)>-- s: a>+++ C++ UL/B>++++$ P+>++++$ L+>++ E--- W+++ N++ o++ K>++ w>--- O? M-- V? PSA+ PE Y+ PGP t 5 X R+ tv++ b++ DI(+) D G e h!(-) r>+ y++*>+++++**$
------END GEEK CODE BLOCK-

login or register to post comments

It's obviously well known

Submitted by andrenym00 on January 3, 2007 - 04:42.

It's obviously well known that the search engines don't read javascript as well as html. When will that change? Does java use the same bandwidth as html or php?

login or register to post comments

I dont belive SE-s can read

Submitted by yahmaster on January 10, 2007 - 23:36.

I dont belive SE-s can read Java at all, they probably see it but reading is I belive very restricted. As far as bandwith is concerned I dont know, and I am also interested.

login or register to post comments

SEs can of course READ js

Submitted by cianuro on January 13, 2007 - 11:09.

SEs can of course READ js files, if you look in your logs, you will see them index external .js files. They just cannot follow js links. If your talking about actual Java applets, then they certainly do NOT index or read them. Dave Davis

login or register to post comments

SE's Spidering Javascript

Submitted by cvos on January 16, 2007 - 04:09.

Search engines have been spidering javascript (both inline and external files) for quite some time. Mostly this is to combat against spam. In addition, Search engines do NOT index code in tags. CSS (both inline and external) are also being crawled. http://www.threadwatch.org/node/11133

login or register to post comments

Yeah I agree that the search

Submitted by giomango on April 15, 2007 - 01:56.

Yeah I agree that the search engines can read java. I have no doubt about it. My t1 line site has java which can be read. I don't think that was the case till recently.

login or register to post comments

The access keys for this page are: ALT (Control on a Mac) plus:

evolt.orgEvolt.org is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.