Tag Archives: JavaScript

Check for Flash-enabled browsers (using JavaScript)

Something most web developers take for granted is the ability of our user’s browser to render Flash. When working with BCD’s product suite, this is particularly true whenever we do any development with SmartCharts. But as you may be aware, there are some browsers which can not actually render Flash objects – namely the iPhone and iPad versions of Safari. These users not only fail to see any of your Flash content, but they also tend to receive a popup error message for every flash object you put on a page. So, in addition to missing out on some key functionality of your page, they also get an annoying alert (or three, or five, or ten…). Continue reading

Objects as parameters in JavaScript functions

Just recently I ran into the issue, that I had a JavaScript function and it needed a lot of values passed in from a WebSmart program. The first option was:

function myfunc(parm1, parm2, parm3, parm4, parm5, parm6){}.

But that means remembering which parameter is on what position, some might even be optional. To avoid the trouble, I decided to use an object instead. The function now looks like this:

function myfunc(obj){}.

And to call it:

  "parm1":"I'm the first",

In the function you can then get to your parameters by using obj.parm1 or obj[“parm1″].

As with jQuery Plugins, you don’t need all name-value-pairs in the object, but you might have to handle missing ones in your function. One way is to set default values.

function myfunct(obj){
  var defaultopts = {"parm1":"", "parm2":false, "parm3":"", "parm4":"", "parm5":0, "parm6":""};
  var options = jQ.extend({}, defaultopts , obj);

The other way is to check if the key exists before using it, otherwise the value will be “undefined”. The JavaScript function has only one parameter, that also means you don’t have to update every function call when you change the object by adding/removing a name-value-pair.