Wednesday, July 09, 2008

jQuery, Google AJAX APIs

We recently implemented jQuery into our ad server, majorly for future feature expansions and hopefully convert some of the existing JS enhancements using jQuery for a simpler codebase. Google AJAX API is nice but does not support SSL, which is quite inconvenient.

Labels:

Wednesday, April 23, 2008

Nested JavaScript inclusions and IE

Consider the following scenario: file.html contains inline JS code to load remote.js and call a function in remote.js And in remote.js You would expect the output in this order and Firefox actually honors this order correctly:
  1. Before loading remote.js
  2. After loading remote.js
  3. In remote function
IE on the other hand will give you an error ("Object Expected") and will call the function prematurely. Meaning that it executes before loading remote.js. This is an unexpected behavior. Fortunately, you can add the attribute defer="defer". This will specifically prevent IE from executing and actually produce proper result. Hmm, it's IE! It has its own style!

Labels:

Saturday, March 15, 2008

JavaScript - setTimeout vs. setInterval

If you need to delay execution (like sleep function), use setTimeout. If you need to repeatedly do something (like refresh stats), use setInterval.
  • window.setTimeout("show();",2000); // wait 2 seconds then run show()
  • window.setInterval("show();",3000); // run show() every 3 seconds

Labels:

Sunday, December 03, 2006

Javascript regular expression in Opera

The following Javascript code works in Firefox & Internet Explorer but not in Opera. Different browsers interpret Javascript code differently. $pTxt = $pTxt.replace(/(.|\n)+<\/tag>/g,''); This code works in all three. $pTxt = $pTxt.replace(/[\s\S]+<\/tag>/g,'');

Labels: