Can i use this JS code for Google adsense - javascript

I see this type of JS codes on so many website for Google adsense ad units.
<!DOCTYPE HTML>
<html>
<head>
<title>Adsense Test</title>
</head>
<body>
<script type="text/javascript">
google_ad_type = 'text';
google_gl = 'default';
google_kw = 'vps';
google_kw_type = 'broad';
google_ad_client = 'ca-xxxxxxxxxxxxxxxx';
google_ad_output = 'js';
google_adtest = 'on';
google_feedback = 'on';
google_language = 'en';
google_encoding = 'utf8';
google_max_num_ads = '20';
function google_ad_request_done(google_ads)
{
var s = '';
var i;
for (i=0;i<google_ads.length;++i)
{
s += '<div class="gad-slot"><pre>';
s += '<strong>'+google_ads[i].line1+'</strong><br />';
s += google_ads[i].line2+ '<br />' + google_ads[i].line3+'<br />';
s += '<small>' + google_ads[i].visible_url + '</small></pre></div>';
}
document.write(s);
return;
}
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</body>
</html>
I want also use this type of code on my site.
Please tell me is legal or illegal for Google adsense policy.

you can't use this code because it is for premium publisher only
https://www.google.com/adsense/premium-login

Related

How do I transfer javascript feed data to php variable?

I need to grab market data from a javascript feed data and convert it to php variables to be later stored in data base.
Here is the javascript data feed code and php page:
` <script type="text/javascript" src="https://files.coinmarketcap.com/static/widget/currency.js">
</script>
<div class="coinmarketcap-currency-widget" data-currencyid="1" data-base="USDT" data-secondary="BTC" data-ticker="true" data-rank="true" data-marketcap="true" data-volume="true" data-stats="USD" data-statsticker="true">
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
var PageToSendTo = "sendprice.php?";
var MyVariable1 = "data-base";
var MyVariable2 = "data-secondary";
var MyVariable3 = "data-stats";
var MyVariable4 = "data-base";
var VariablePlaceholder = "btcprice";
var UrlToSend = sendprice.php? + data-base + btcprice;
xmlhttp.open("GET", UrlToSend, false);
xmlhttp.send();
<?php
$btcprice = $_GET['btcprice'];
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<meta name="author" content="Portal Associates" />
<title>Untitled 3</title>
</head>
<body>
<?php
echo $btcprice;
?>
</body>
</html>
`
I want to be able to capture realtime data and store it in db for chart generation. I am not a javascript programmer. Please enlighten me.
Thanks in advance,
Batoe
Try this:
JavaScript:
var MyVariable1 = "data-base";
var MyVariable2 = "data-secondary";
var MyVariable3 = "data-stats";
var MyVariable4 = "data-base";
var VariablePlaceholder = "btcprice";
var UrlToSend = "sendprice.php";
var params = VariablePlaceholder + '=' + MyVariable1 + '&MyVariable2=' + MyVariable2 + '&MyVariable3=' + MyVariable3 + '&MyVariable4=' + MyVariable4;
xmlhttp.open( "GET", UrlToSend + '?' + params, false );
xmlhttp.send();
PHP (in sendprice.php):
$btcprice = $_GET['btcprice'];
$MyVariable2 = $_GET['MyVariable2'];
$MyVariable3 = $_GET['MyVariable3'];
$MyVariable4 = $_GET['MyVariable4'];

Copying file names from upload to textarea

I have a code that will copy the file names and add them to the textarea. Everything works but when you add more files, the first ones are deleted. How to fix it?
updateList = function() {
var input = document.getElementById('file');
var output = document.getElementById('fileList');
output.innerHTML = '';
for (var i = 0; i < input.files.length; ++i) {
output.innerHTML += '\n' + input.files.item(i).name + '';
}
output.innerHTML += ' \n';
}
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Display file name in page after selecting file in file input</title>
</head>
<form>
<input type="file" name="file" id="file" multiple
onchange="javascript:updateList()" />
<br/>Selected files:
<textarea id="fileList"></textarea>
<script src="js/index.js"></script>
</body>
</html>
FIDDLE: https://jsfiddle.net/yhw8zfue/
You are setting your textarea value to empty string.
You can fix by removing the line:
output.innerHTML = '';
When you add more files the function will run again and updste your filelist. but in your code you reset the list of files here:
output.innerHTML = '';
so instead you want to have whats currently in there. replace it with that:
updateList = function() {
var input = document.getElementById('file');
var output = document.getElementById('fileList');
output.innerHTML = output.value;
for (var i = 0; i < input.files.length; ++i) {
output.innerHTML += '\n' + input.files.item(i).name + '';
}
output.innerHTML += ' \n';
}

How to display information relative to image clicked using pokemon API?

I'm trying to get and display the image and information of a clicked pokemon from pokemon API
HTML code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script src="pokedex2.js"></script>
<link rel="stylesheet" href="pokedex2.css">
<title>Pokedex v 2.0</title>
</head>
<body>
<div id="all">
<div id="pokemon">
</div>
<div id="chosen">
</div>
</div>
</body>
</html>
JavaScript
$(document).ready(function(){
for(i = 1; i <=151; i ++){
$("#pokemon").append("<img id=pokepic" + i + "
src='http://pokeapi.co/media/img/" + i +
".png'>");
}
var clicked = false;
$("img").click(function(){
clicked = true;
console.log(this);
if(clicked){
$.get("http://pokeapi.co/api/v1/pokemon/" + i +"/", function(data){
var str = "";
str += "<h4>Types</h4>";
str += "<ul>";
var str2 = "";
str2 += "<h4>height</h4>";
str2 += "<ul>";
var str3 = "";
str3 += "<h4>weight</h4>";
str3 += "<ul>";
for(i = 0; i < data.types.length; i ++){
str += "<li>" + data.types[i].name + "</li>";
}
str2 += "<li>" + data.height + "</li>";
str3 += "<li>" + data.weight + "</li>";
str += "</ul>"
str2 += "</ul>"
str3 += "</ul>"
$("#chosen").html(str + str2 + str3); }, "json");
}
else{
clicked = false;
}
})
});
At the moment, the only information being brought up are for the first 3 pokemon in the list, not for the pokemon that was clicked. I need to find the information associated with the clicked pokemon, like a pokedex.
I included console.log to show that whichever image is clicked, the picture, and pokepic ID number associated with that image appear in the console. Instead what I need is for the image and stats associated with each image to appear in the div labeled chosen
Your click event uses the i variable defined in your for loop. Since the function inside the click is always called after the loop is done, i is always 152. You need to read the current pokemon from your click event:
$('img').on('click', function(e){
var pokemonId = e.target.id.split('pokepic')[1];
$.get("http://pokeapi.co/api/v1/pokemon/" + pokemonId +"/", function(data){
...
});
});

Geo Location Trace getElementById not working

I am working on a challenge by freecodecamp, Task is to show the local weather and hence I have to get the location of the user. I can get the location from here but after printing that i was trying to getElementById of a div i have printed using JS which gives null in response. I want to get the key value pair so that i can do stuff with them. Here is my code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Location Trace | freecodecamp Challanges</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<div id="GeoResults"></div>
<script>
$.getJSON("http://ip-api.com/json/?callback=?", function(data) {
var table_body = "";
var count = 0;
$.each(data, function(k, v) {
//JSON.stringify(j); // '{"name":"binchen"}'
table_body += '<div id=Coun_'+count+'>'+v+'</div>';
//table_body += "<tr><td id='FC_"+count+"'>" + k + "</td><td><b id='SC_"+count+"'>" + v + "</b></td></tr>";
count++;
});
$("#GeoResults").html(table_body);
});
</script>
<script>
var x = document.getElementById('Coun_1') /*= 'Dooone!!!'*/;
console.log(x);
</script>
</body>
</html>
Thanks in Advance!
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Location Trace | freecodecamp Challanges</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<div id="GeoResults"></div>
<script>
$.getJSON("http://ip-api.com/json/?callback=?", function(data) {
var table_body = "";
var count = 0;
$.each(data, function(k, v) {
//JSON.stringify(j); // '{"name":"binchen"}'
table_body += '<div id=Coun_'+count+'>'+v+'</div>';
//table_body += "<tr><td id='FC_"+count+"'>" + k + "</td><td><b id='SC_"+count+"'>" + v + "</b></td></tr>";
count++;
});
$("#GeoResults").html(table_body);
var x = document.getElementById('Coun_1').innerHTML; /*= 'Dooone!!!'*/;
console.log(x);
});
</script>
</body>
</html>

For loop producing 'undefined' before iteration output

I'm stumped as to why my for loops are displaying "undefined" before any of my actual output occurs. I have all variables declared, and using Inspect Element shows no syntax errors.
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function(){
"use strict";
var html, s, vindex;
var v = ['alpha::one::uno', 'beta::two::dos', 'gamma::three::tres'];
for (vindex = 0; vindex < v.length; vindex++) {
s = v[vindex].split('::');
html += '<div class="inline ' + s[0] + '">\n';
html += '<h4>' + s[1] + '</h4>';
html += '' + s[2] + '</div>';
}
$("div").append( html );
});
</script>
</head>
<body>
<div></div>
</body>
</html>
http://jsfiddle.net/a5b6C/1/
The undefined string shows up because html is undefined
var html, s, vindex;
var html; is basically the same thing as var html = undefined;
Set it as an empty string.
var html = "", s, vindex;

Categories