[Xerte-dev] Reading url parameters in Xerte via javascript - strange behaviour in IE8

Kemp Johnathan johnathan.kemp at ntlworld.com
Wed Apr 18 22:23:58 BST 2012


Recently I have been working on opening up Xerte projects via a url which
includes a parameter to specify which page to open the project at.

I have a javascript function which returns a url parameter, you pass the
name of the parameter in the function call and it returns the value for the
parameter if that parameter name has been included in the url.

When included in a html page it works reliably in IE8, Opera and Firefox.

However when I add the function to the end of rloObject.js and open the
Xerte project with a url like the following (running a Xampp install of XOT)

http://localhost/toolkits/play.php?template_id=20&pageID=bullet

and including in a script in the Xerte project the lines

destinationPage = callJS("myFunction","pageID");
callJS("alert"," destinationPage = " + destinationPage );

In Opera or Firefox I get an alert box that displays "destinationPage =
bullet"
but in IE8 I get an alert box that displays " destinationPage = null"

If I use the Developer Tools in IE 8 and put a break point in my function I
can watch the parameter be correctly gathered by the javascript function
and returned.

The debugger then shows the next stage in the process as being back in the
flash environment with the current line shown in yellow below

function __flash__escapeXML(s) {
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g,
">").replace(/"/g, """).replace(/'/g, "'");
}
function __flash__toXML(value) {
var type = typeof(value);
if (type == "string") {
return "<string>" + __flash__escapeXML(value) + "</string>";
} else if (type == "undefined") {
return "<undefined/>";
} else if (type == "number") {
return "<number>" + value + "</number>";
} else if (value == null) {
return "<null/>";
} else if (type == "boolean") {
return value ? "<true/>" : "<false/>";
} else if (value instanceof Date) {
return "<date>" + value.getTime() + "</date>";
} else if (value instanceof Array) {
return __flash__arrayToXML(value);
} else if (type == "object") {
return __flash__objectToXML(value);
} else {
return "<null/>"; //???
}
}

If I set a watch on "value" it correctly displays in the watch with the
value of the url parameter
i.e. if my url has &pageID=bullet, and I called my function with
destinationPage = callJS("myFunction"."pageID");
then the watch shows "value" to be "bullet"

Since the type is a string the function  __flash__escapeXML(s) gets called.

If I set a watch on s in this function then this also displays with the
value of "bullet"

However when you step beyond the line

return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g,
">").replace(/"/g, """).replace(/'/g, "'");

the debugger changes to display

try { __flash__toXML(alert("destinationPage = null")) ; } catch (e) {
"<undefined/>"; }

I don't know if the functions revealed by the debugger are part of Xerte or
part of the browser's flash player, but the problem appears to lie here in
that somehow even though the javascript has been able to return the url
parameter to the flash environment, the flash environment is then returning
a value of "null".

If I can overcome this problem then it should be possible to call a XOT
project via a url and open the project at a specific page in IE8, just as I
now can if the project is opened in Firefox or Opera.

Can anyone with more knowledge of the Flash side of things cast any light
on what is going wrong or how to fix this?

Kind regards

Johnathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nottingham.ac.uk/pipermail/xerte-dev/attachments/20120418/afa28a40/attachment.html>


More information about the Xerte-dev mailing list