I implemented Paul's suggestion. True, it's not pretty but it works.
First, I gave the <a> element containing the callback an id in order to be able to script against it like:
- Code: Select all
<a id="standout" onclick="javascript:globals.callback()">...</a>
Second, I added this function to the <head> of my html:
- Code: Select all
function changeCallbackArgs(callBackId, args) {
var o = document.getElementById(callBackId);
o.outerHTML = o.outerHTML.replace(/(.*)globals\.callback\(.*\)(.*)/,"$1globals.callback(\\'" + args + "\\')$2");
}
Third, I added a call to the
changeCallbackArgs function to the onclick of the html element I want to dynamically set the callback parameters like:
- Code: Select all
<a onclick="changeCallbackArgs('standout,'myDynamicValue')">...</a>
The main drawback in this sollution is that I need to create a changeCallbackArgs function for each callback function because the name of the callbackfunction is part of the literal regExp. I tried to create a more generic function like this:
- Code: Select all
function changeCallbackArgs(callBackId, callBackMethod, args) {
var o = document.getElementById(callBackId);
var pattern = "(.*)globals\."+callBackMethod+"\(.*\)(.*)";
var re = new RegExp(pattern);
o.outerHTML = o.outerHTML.replace(re,"$1globals."+callBackMethod+"(\\'" + args + "\\')$2");
}
The problem seems to be that the
\(.*\) does not match anything in this construction so the 2nd group matches the rest of the string. It's the same pattern but somehow, creating a regExp object first does not match the same strings as in the first example.
Any regExp javascript guru's out there ?