views:

551

answers:

3

Hi there,

I have been using DWR for couple of months in my project. i tried using dwr's util.js in one of my jsp but strangely when i include util.js(version 2.0.1) none other javascript is working in internet explorer(working fine in mozilla) .

i am trying to manipulate tables with util.js as described here and more surprisingly i can't even see the link functioning well in Internet Explorer.

has anyone come across this. any help?

thanks!

+1  A: 

By any chance are you also using jQuery, Prototype, or another JavaScript language that uses the $ function?

The 2.x versions of DWR Alias dwr.util.byId as "$" (which is deprecated, since it isn't as powerful/helpful as the $ in jQuery, Prototype or similar).

They tried to be clever, and only do the Alias, if $ wasn't pre-defined, but the check logic is flawed.

I presume at first they did this:

if(!$){
  //... alias it
}

but then someone realized that if $ wasn't defined, this would throw an error, so it was commited as:

var $;
if(!$){
  //... alias it
}

which works fine in Firefox as this doesn't declare a value for $, just that it exists.

But in Internet Explorer, the var statement re-defines $ as (nothing)... thus it doesn't exist when the if() test is run...

Checking the 3.x (RC) code, they ditched this test for the more stable:

if(window['$'] == null){
  //... alias it
}

Which works fine in Firefox AND Internet Explorer (& AFAIK all other browsers)... just update the util.js file in your dwr.jar.

I should also note: the order in which you include libraries will determine which one gets ownership of the $ function.

e.g. to let jQuery have it, do:

<script src="jQuery"...></script>
<script src="dwr/util.js"...></script>

to let DWR have it, be sure to set the noConflict flag for jQuery

<script src="jQuery"...></script>
<script>jQuery.noConflict();</script>
<script src="dwr/util.js"...></script>

Docs: jQuery.noConflict

scunliffe
Thank you! awesome explanation.
sangram
A: 

Wow, dude, that was 'exactly' what was wrong with mine too. Great, concise answer! I've been searching the internet for hours trying to find this. Thanks!

Walter
A: 

you are great,thank you!

richard