/    Sign up×
Community /Pin to ProfileBookmark

Javascript function to output a javascript?

I am trying to make a javascript to display ads in MediaWiki templates because it does not support javascript in its templates. What I did is surround the template in <div id=”infobox”></div> then tried to make a javascript function that outputs the ads, however it is not working. Here are two variations of the script I tried using, and neither works.

This function doesn’t display the ads.

[CODE]function addAdSense() {
var div = document.getElementById(‘infobox’);
if(!div) return;
var script = document.createElement(‘script’);
script.src = ‘<script type=”text/javascript”><!–
google_ad_client = “pub-XXXXXXXXXXXXXXXX”;
/* Infobox */
google_ad_slot = “XXXXXXXXXXXX”;
google_ad_width = 250;
google_ad_height = 250;
//–>
</script>
<script type=”text/javascript”
src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”>
</script>’;
div.appendChild(script);
}
addOnloadHook(addAdSense);[/CODE]

This function doesn’t let the page load at all.

[CODE]function addAdSense() {
var div = document.getElementById(‘infobox’);
if(!div) return;
google_ad_client = “pub-XXXXXXXXXXXXXXXX”;
google_ad_slot = “XXXXXXXXXXXX”;
google_ad_width = 250;
google_ad_height = 250;
var script = document.createElement(‘script’);
script.type = ‘text/javascript’;
script.src = ‘http://pagead2.googlesyndication.com/pagead/show_ads.js’;
div.appendChild(script);
}
addOnloadHook(addAdSense);[/CODE]

Any help is greatly appreciated.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@mrhooMar 10.2008 — Yeah, we all think that wikis would be better if they just had more advertising.
×

Success!

Help @fishnchips spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.30,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...