1
votes

I am using joomla on this site. I have an affilate program that requires me to run the following html on my page:

Header

var bid= ####; var site =#; document.write('');

Footer

the following url is delivered and does not work (shows a email form) http://www.whatshappeningnow.info/index.php/index.php?option=com_content&view=article&id=764?evtid=1626579&event=ZZ+Top

Note the "?" between "=764" and "evtid="

If I change the url to:

http://www.whatshappeningnow.info/index.php/index.php?option=com_content&view=article&id=764&evtid=1626579&event=ZZ+Top

Note:I replaced the "?" with "&"

Now the correct results do display (the css needs to be adjusted, but the tickets do display!

How do I make my url write correctly from there script that I can not change.

2
The best thing to do would be to talk to the affiliate program and ask them to fix their bugs. - Pekka
You say the url is "delivered". How is it delivered? - squidbe
I created a html page which includes a javascript for a window location search substring and they produce the results from there data base on my html page. The results page that you see above includes the search string and that is what is making the page not show. again if I change THEIR "?" to "&" which is what their plug in script documentation calls for the page shows correctly. - raymond

2 Answers

1
votes

As one comment says, the best thing to do is get in touch with the affiliate program and let them fix this.

As a workaround, you could transform the URL that is returned by the affiliate program script. Since in a URL only one "?" is allowed, you could split the URL in substrings at "?"s and then rebuild it by only putting the "?" between the first and second substrings. Something like this:

var newUrl = "";
var urlSubs = affiliateUrl.split("?");
if (urlSubs.length === 0) {
   newUrl = affiliateUrl;
   //-- no "?", do your processing here...
} else {
    newUrl = urlSubs[0] + "?";
    var i = 1;
    for (i = 1; i < urlSubs.length; i++) {
       newUrl = newUrl + "&" + urlSubs[i];
    } 
}

NB: I have not considered any error checking!

This will work for any number of "?", and will only keep the first one.

0
votes

As Pekka pointed out, the best thing is to get them to fix that bug, but in the meantime, you could do something like this assuming you can somehow access the string they return:

<script>
var str = "http://www.whatshappeningnow.info/index.php/index.php?option=com_content&view=article&id=764?evtid=1626579&event=ZZ+Top";
var newStr = str.replace(/(\?)([^\?]*)(\?)/, "$1$2&");
</script>

This only works if you know that the string will always have two question marks, one in the correct place and one where an ampersand should be. It finds the appropriate string using a regular expression and simply replaces the 2nd "?" with an ampersand.