I have such an Adsense code:
<script type="text/javascript"><!--
google_ad_client = "ca-pub-12345";
/* my advertisement */
google_ad_slot = "2345";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
I have such an js file:
$(document).ready(function() {
var adsenseCode='<script type="text/javascript"><!--
google_ad_client = "ca-pub-12345";
/* my advertisement */
google_ad_slot = "2345";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
$().append(adsenseCode);
}
I tried with double quotes, single quotes, removing comment lines etc. Not found the solution.
How can I print javascript code inside my HTML page?
something like the following should do the trick…
.append()call so that it will append to the document’s<head>block.</script>end tags to avoid confusing the browser if this code is, itself, located within a<script>...</script>block. This may or may not be necessary, depending on browser versions, doctypes, and other things, but I think it’s generally a good idea for safety’s sake.As @DarkFalcon notes in the comments, jQuery’s append function may prevent scripts with external sources from being loaded. I’ve experimented with this a bit, and it doesn’t seem to be a problem though. Let us know if this works or not. If it doesn’t, we can explore other alternatives.