Hey, I am trying to further my knowledge of javascript and was wondering if anyone could explain to me what exactly is happening in the script below:
<– Begin Google Adsense code –>
<script type=”text/javascript”>
google_ad_client = “ad-client-code-goes-here”;
google_ad_slot = “ad-slot-code-goes-here”;
google_ad_width = 300;
google_ad_height = 250;
</script>
<script type=”text/javascript”
src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”>
</script>
<– End Google Adsense code –>
Most importantly, why are there 4 'google_ ad_ ...' at the beginning and what is the purpose of them?
A line by line explanation would be awesome :)
Thanks for any help. I really appreciate it.
The google_ad... are variables (associate this code to your account, set width/height of ad, etc). They're being set for the script (show_ads.js) that will later be loaded.
For a full rundown of the variables, see CyberNAC Javascript Variables used in Adsense.
Related
First off, I am NOT a professional programmer, which is why I am here for help, so thanks in advance for your time and patience. I need a bit of code for a website that will call and display information from a specific field in a published Google spreadsheet, to be displayed via HTML, through javascript or some other similar method.
Looking around, there seems to be several ways of doing this, but all of the examples and tricks I can find are a bit beyond my expertise, and my efforts at applying several of those methods have, frankly, failed miserably. I have searched through previous questions, but they all cite examples that are way more complicated than what I need.
If someone could cite me an easy example, I'd greatly appreciate it. (The simpler the better.) In the meanwhile, I will continue to experiment to see what I can do.
This is a duplicate of How can I access Google Sheet spreadsheets only with Javascript?
But since that example is not trivial for beginners, here is the code that will show the second cell of the spreadsheet using the code from the answer above
Go to https://github.com/mikeymckay/google-spreadsheet-javascript and download the file google-spreadsheet.js
Edit that file with a text editor and change
this.jsonCellsUrl = "http:// to this.jsonCellsUrl = "// and
this.jsonListUrl = "http:// to this.jsonListUrl = "//
to not have mixed http and https in your page
Change the var url in the below to point your sheet
FIDDLE
<!DOCTYPE html>
<html>
<head>
<title>Spreadsheet example</title>
<script type='text/javascript' src='//code.jquery.com/jquery-1.11.0.js'></script>
<script type='text/javascript' src='google-spreadsheet.js'></script>
<script type='text/javascript'>
$(function() {
var url = "https://spreadsheets.google.com/pub?key=0Ago31JQPZxZrdHF2bWNjcTJFLXJ6UUM5SldEakdEaXc&hl=en&output=html";
var googleSpreadsheet = new GoogleSpreadsheet();
googleSpreadsheet.url(url);
googleSpreadsheet.load(function(result) {
$('#results').html(result.data[1]); // show the 2nd (0-based) cell
});
});
</script>
</head>
<body>
Here is the result: <span id="results"></span>
</body>
</html>
I try to embed this zippyshare player
<script type="text/javascript">var zippywww="54";var zippyfile="JnIxIFUy";var zippytext="#000000";var zippyback="#e8e8e8";var zippyplay="#ff6600";var zippywidth=850;var zippyauto=false;var zippyvol=80;var zippywave = "#000000";var zippyborder = "#cccccc";</script><script type="text/javascript" src="http://api.zippyshare.com/api/embed_new.js"></script>
into a html file on my pc! When I do this and open it, it will show nothing!
Any idea to do this or why it don't work?
Thanks a lot
This is old but kind of interesting since their embed code didn't work out-of-the-box for me either.
Here's how I managed to embed the Zippyshare player into my html for anyone facing this same issue.
If you look at the embed code, there is this <script type="text/javascript" src="http://api.zippyshare.com/api/embed_new.js"></script> at the end of all the declared parameters. Copy that url http://api.zippyshare.com/api/embed_new.js into your browser and there's the iframe you are looking for... right?
This is what it looks like:
var a = navigator.userAgent||navigator.vendor||window.opera;
document.write("<iframe height=\"92\" width=\""+zippywidth+"\" frameBorder=\"0\" src=\""+window.location.protocol+"//api.zippyshare.com/api/jplayer_embed.jsp?key="+zippyfile+"&server=www"+zippywww+"&width="+zippywidth+"\"></iframe>");
Somehow, however, your webpage never receives this. So I copied that part and pasted into my html code, replacing the zippyshare script call and modifying it a bit (replacing escape characters with single quotes). So my html now looks like this:
<body>
<script type="text/javascript">
var zippywww="20";
var zippyfile="CyeL81Cn";
var zippytext="#000000";
var zippyback="#e8e8e8";
var zippyplay="#ff6600";
var zippywidth="100%";
var zippyauto=false;
var zippyvol=80;
var zippywave = "#000000";
var zippyborder = "#cccccc";
var a = navigator.userAgent||navigator.vendor||window.opera;
document.write("<iframe height='92' width='"+zippywidth+"' frameBorder='0' src='http://api.zippyshare.com/api/jplayer_embed.jsp?key="+zippyfile+"&server=www"+zippywww+"&width="+zippywidth+"' allowfullscreen></iframe>");
</script>
<!--script type="text/javascript" src="//api.zippyshare.com/api/embed_new.js"></script-->
</body>
It works, BUT I still wouldn't recommend it as it defeats the core purpose of having an api call. So this is not as much an answer as it is a very temporary fix :) while you figure it out or while Zippyshare figures out what to do with all those unused customization parameters you specify.
I have one piece of code as:
<script type="text/javascript"><!--
google_ad_client = "ca-pub-8514414755716493";
/* AdX_Washington_Examiner */
google_ad_slot = "9465392777";
google_ad_width = 320;
google_ad_height = 50;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
Why this code is giving output as "}//]]>" ??
I have not written any print call still it is giving output..
Here is my fiddle link http://jsfiddle.net/akshaynikte/ryLPf/6/#
Here are a few excerpts from the jsFiddle documentation page :
The JavaScript panel
Code entered in this panel will be placed in header’s script block,
that is between <script type="text/javascript"> and </script>.
The Add Resources section
CSS or JS (with appropriate extension) which should be loaded after
the framework. It’s a perfect place to put libraries which are
framework independent, like RaphaelJS
So, the correct way to work with the script in your question would be:
Add the following to the JavaScript panel.
<!--
google_ad_client = "ca-pub-8514414755716493";
/* AdX_Washington_Examiner */
google_ad_slot = "9465392777";
google_ad_width = 320;
google_ad_height = 50;
-->
Add http://pagead2.googlesyndication.com/pagead/show_ads.js to the Add resources section on the left side of the page.
Here's a link to a properly configured sample: http://jsfiddle.net/edywd/.
It seems to be a bug on fiddler (or that it doesn't allow script tags on javascript panel) , if you change the script to anything else, you'll see that it happens the same.
You should place your script on HTML panel, that works fine according my tests.
<script type="text/javascript"><!--
google_ad_client = "ca-pub-8514414755716493";
/* AdX_Washington_Examiner */
google_ad_slot = "9465392777";
google_ad_width = 320;
google_ad_height = 50;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
you cant use script tags in js textarea of jsfiddle,it is js only, if you want use script tags , put them in the html textarea of jsfiddle
I would like to place a javascript (adsense) code inside the post (not above or after the post). It will be a HTML page.
Is there any way i can put my adsense code in external Js file and i will use one function to display it.
adsense code looks something like
<script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxxxx";
google_ad_host = "pub-xxxxxxxxxxxxxxxx";
google_ad_slot = "xxxxxxxxxx";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
So if i call a function CallMe() which will start showing ad wherever i have used the function. In future if i would like to replace ad code with another code then i dont want to go to each post and replace it. I will just replace the adcode from js file.
I am a newbie and have just started learning JavaScript so i am really not aware if it can be done or not.
Any suggestion ?
Create file called AdSense.js with the following code:
google_ad_client = "pub-xxxxxxxxxxxxxxxx";
google_ad_host = "pub-xxxxxxxxxxxxxxxx";
google_ad_slot = "xxxxxxxxxx";
google_ad_width = 336;
google_ad_height = 280;
function ApplyAdSense() {
var oScript = document.createElement("script");
oScript.type = "text/javascript";
oScript.src = "http://pagead2.googlesyndication.com/pagead/show_ads.js";
document.getElementsByTagName("head")[0].appendChild(oScript);
}
Now whenever you want adsense in your code, first include the file:
<script type="text/javascript" src="AdSense.js"></script>
Then call the function:
<script type="text/javascript">
ApplyAdSense();
</script>
This way, until you call the function nothing happens.. and you can also comment the code inside the function to disable adsense throughout all your site.
Wherever you want the ad to show up, place this code (assuming you have a function called CallMe).
<some html>
<script type="text/javascript">CallMe();</script>
</some html>
If your concern is about the page loading time, Adsense released the asynchronous version of their Adsense code. Please see https://support.google.com/adsense/answer/3221666?hl=en
Whenever I minify the AdSense script I got from Google, it stops working. Any ideas why?
Original Code:
<script type="text/javascript"><!--
google_ad_client = "xxx";
/* Ad 1 */
google_ad_slot = "2668798369";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
Minified Code:
<script type="text/javascript"><!--google_ad_client = "xxx";/* Ad 1 */google_ad_slot = "2338787596";google_ad_width = 200;google_ad_height = 200;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
The minification is being done by Smarty's {strip} tags.
The problem is the HTML comment tags at the start and end of the first script tag. You don't need them, they're just there to work around Netscape 1.0
Try replacing your minified script with this
<script type="text/javascript">google_ad_client="xxx";google_ad_slot="2668798369";google_ad_width=160;google_ad_height=600;</script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
i think you left out this part:
//-->
Try to remove the <!--
Hope it helps
It'll be the <!-- - this can mean 'treat this line as a comment'. It's an old compatibility hack for browers that didn't support JavaScript.
Either remove it or add a linebreak afterwards, i.e.
<script type="text/javascript"><!--
google_ad_client="xxx"; ...
though I can't see what minifying here is gaining you - there's nothing that can be renamed or compressed.
Look out for this:
<!-- and -->