This has been kicking me for the last 12 hours, and based on various help sections and forums which shall not be named, it seems to be causing a bit of trouble for others as well.
I’m working with a modified version of OpenAds. Yes I modified it, but before you say “crap, Gracie modified something…no wonder it’s broken” I’ll just advise you to put a lid on it – the project still works. I’m playing with delivering ads using the remote Javascript, but I’ve got a hitch. Each page I’m trying to deliver a text ad to is a search result that has a keyword associated with it. I’ve passed that keyword onto the page using the variable $tagString
– it’s url encoded. I can print that keyword by placing {$tagString}
anywhere in the template code. So I know the variable is there.
Now I’m trying to pass $tagString
into the chunk of Javascript, and it just isn’t working. I’ve tried different notations such as %24tagString
etc., and tried adding things like var tagstring = $tagString
at the top, but the Javascript ad code just doesn’t see the variable. In addition, I replaced the variable with an actually keyword string and it returned the correct result so I’m certain it isn’t a server side issue. The ad code is below, and if anyone has any bright ideas they can pass along I would forever be in your debt gladly take you out for a beer someday. I’ll certainly pass this on to the OpenAds community if someone can figure it out. Note: XXX
denotes the spot where the variable $tagString
is supposed to go.
src='http://adserver.com/ads/adx.js'></script>
<script language='JavaScript' type='text/javascript'>
<!--
if (!document.phpAds_used) document.phpAds_used = ',';
phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);
document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
document.write ("http://adserver.com/ads/adjs.php?n=" + phpAds_random);
document.write ("&what=zone:1&source=XXX");
document.write ("&exclude=" + document.phpAds_used);
if (document.referrer)
document.write ("&referer=" + escape(document.referrer));
document.write ("'><" + "/script>");
//-->
</script><noscript><a href='http://adserver.com/ads/adclick.php?n=1234abcd' target='_blank'><img src='http://adserver.com/ads/adview.php?what=zone:1&source=XXX&n=1234abcd' border='0' alt=''></a></noscript>
Comments
I’ve gotten halfway there…
Added the following lines after script language:
var tagstring;
tagstring = “something”
Replaced the first XXX with this: ” + tagstring
and the second with: ‘+tagstring+’
Now I can replace “something” with a known variable and everything works – problem now is getting the page variable in there in place of “something”.
Solved.
tagstring = “something” has been changed to:
tagstring = encodeURIComponent(location.pathname); (or “location.search” as the case may be)
since the path of the url is actually the variable. So $tagString is no longer needed either.