Menu

#19 SWFAddress workaround for Webkit bug breaks when base set

open
nobody
None
5
2010-07-08
2010-07-08
Ciro Durán
No

We recently upgraded the SWFAddress version from 2.2 to 2.4 in our Flex project. Our Flex project consist in a main application with several sections inside, and that's where SWFAddress acts. Each section has a URL slug, so when you click a section the URL Address goes to "#sectionX", and when you return to the home section the URL Address goes to "#".

Now, the SWF files reside in http://example.com/flex, but the SWF is served by a Java action, say http://example.com/application.do. Given this configuration, the jsp served by application.do has a tag pointing to the /flex directory.

SWFAddress 2.4 works as expected in IE and Mozilla: when you enter http://example.com/application.do, and you click a section, it goes to http://example.com/application.do#sectionX, and when you return to home, it goes to http://example.com/application.do#.

This behavior is not observed in Webkit-based browsers (e.g. Safari/Chrome): when you enter http://example.com/application.do, and you click a section, it goes to http://example.com/application.do#sectionX, but when you return to home, it goes instead to the base of the jsp served by application.do, namely "http://example.com/flex#". There is no index in the flex directory, so it returns a 404. The expected behavior is to return to http://example.com/application.do# as it does in IE and Mozilla, and as SWFAddress 2.2 does (our previous version).

Now, when debugging this issue using swfaddress-uncompressed.js, I found this in lines 672-678, at the definition of the setValue function, the one that I use to set the URL:

} else if (_version < 523 || _value == '') {
var evt = _d.createEvent('MouseEvents');
evt.initEvent('click', TRUE, TRUE);
var anchor = _d.createElement('a');
anchor.href = '#' + _value;
anchor.dispatchEvent(evt);
} else {

The call enters to this code only for safari/webkit browsers. While setValue uses the Location object for the rest of the browsers, and replaces the Location with the desired value, in Safari instead whenever you set the value to an empty string you enter this piece of code, which basically does is create an "a" element, set its corresponding "href" attribute with the value "#", and fire a click event.

Now, because the jsp served by application.do had a set (remember, "flex/"), in Safari instead of creating an <a href="#"> element and clicks it, it creates an <a href="http://example/com/flex/#"> element, and clicks it, thus leaving me in the wrong address.

Although I do know how to use Actionscript, I do not have experience with Javascript and its browser quirks, so I'm a bit helpless around here. Is it possible to have this code to take the base into account?

Discussion


Log in to post a comment.

MongoDB Logo MongoDB