URL to check if IP is in the EU - json

Does anyone know if there's a service to check if an IP address is in the EU? I'm trying to implement a cookie notification on my website but I only want to show it if it's required by law.
I'm trying to implement this using AMP, and it gives the option to use a URL to check if the notification should be displayed. I know this is probably a long shot, but it needs to return a result like this: (based on the URL the request came from).
{
"showNotification":true
}
I'll probably just end up creating something, just wanted to check on the off chance that someone already did

I just figured out how to do this with amp-geo - I thought I'd share the answer in case anyone else came across it:
Include these JS files:
<script async custom-element="amp-user-notification" src="https://cdn.ampproject.org/v0/amp-user-notification-0.1.js"></script>
<script async custom-element="amp-geo" src="https://cdn.ampproject.org/v0/amp-geo-0.1.js"></script>
Include this code:
<amp-geo layout="nodisplay">
<script type="application/json">
{
"ISOCountryGroups": {
"ineu": ["al","ad","at","az","by","be","ba","bg","hr","cy","cz","dk","ee","fi","fr","ge","de","gr","hu","is","ie", "it","kz","xk","lv","li","lt","lu","mk","mt","md","mc","me","nl","no","pl","pt","ro","ru","sm","rs","sk", "si","es","se","ch","tr","ua","gb","va"]
}
}
</script>
</amp-geo>
<amp-user-notification id="cookie-notif" layout="nodisplay" data-show-if-geo="ineu">
<div>
This site uses third-party cookies, learn more or <a on="tap:cookie-notif.dismiss" class="ampstart-btn caps ml1">accept</a>
</div>
</amp-user-notification>

Related

Which Captcha or related is easy to is install on form?

I am a newbie to programming and I already struggled a lot for a week to have a fully functional form that validates, stores data, and then redirects.
Please let me know about a captcha that is easy to install and doesn't mess up my code resulting in data not being sent to PHP which javascript did to me.
A very cheap way of doing a quick and dirty check could be something like this:
<form name="form" method="post">
<!-- your other form fields -->
<input type="text" id="title" name="title" value="somethingsomething">
<input type="submit" value="send">
</form>
You can make the field invisible and choose a name, that a bot would definitely fill out. Choose anything meaningful just not something like "antispam" or the like.
input#title {
visibility: hidden;
height: 0;
width: 0;
}
And then just check if the input field got set:
<?php
if (isset($_POST["title"])) {
// a bot had filled the field now, do something
}
?>
The concept is called "honeypot". You can also check out this stackoverflow post here:
Better Honeypot Implementation (Form Anti-Spam)
You can use the google cpatcha.
You do not have to code at all
Procedure
1.Log on to your Google account.
2.Access https://www.google.com/recaptcha/adminInformation published on non-SAP site from your browser.
3.Select the Invisible reCAPTCHA radio button.
4.Register your domain.
Remember
Your domain is the URL of your Identity Authentication tenant. It has the <tenant ID>.accounts.ondemand.com pattern.
Tenant ID is automatically generated by the system. The first administrator created for the tenant receives an activation e-mail with a URL in it. This URL contains the tenant ID.
5.Save your Site key and your Secret key. You need them for the configuration steps in the administration console for Identity Authentication.
Source of answer
[Try this
The best CAPTCHA codes
No CAPTCHA reCAPTCHA
Image CAPTCHA
add a CAPTCHA to your website
][1]
document :- url [1]: https://internet.com/website-building/how-to-add-a-captcha-to-your-website/
Try this:
Register an hcaptcha account and follow it's instructions.
Add <script src="https://hcaptcha.com/1/api.js" async defer></script> to your head if you have not already done so
Add <div class="h-captcha" id="captcha" data-sitekey="INSERT SITEKEY HERE" data-theme="dark"></div> (Leave data-theme="dark" in for dark theme).
In your form tag, add onsubmit="return checkCaptcha()" as an attribute, like so: <form onsubmit="return checkCaptcha()">
Add the function below to your JS code:
function checkCaptcha() {
if (hcaptcha.getResponse() == "") {
return false;
} else {
return true;
}
}

Make a link appears on a page only if the visitor is one of my subscribers?

I wonder if there is any way to, on a page of my website, show a link or a div only if the visitor subscribed to my channel, with api's or something ? I already saw something like this with facebook in the past but now i'd like to use this kind of thing. Is it possible in any kind of way ?
you can achieve this in many ways depending on how are you checking witherthe user is a subscriber or not
if you store this in a bool value then all you need is a bit of javascript
<html>
body>
<a href ="#" class = "hidden"/>
</body>
$(function(){
var isSubscribed = //Here the value;
if(isSubscribed )
{
$(a).removeClass('hidden');
}
})
if you are using any server side language then it will be far easier

Difficulties With Button Functionality

Good Day,
I am working through freecodecamp and am currently grappling with the quote generator problem. I have run into a bit of an issue with getting functionality for me scripting a change when clicking the button. Basically I have my own code which I'll post below, but also trying to simply copy and paste the code from them I am still unable to get functionality in my button.
I am sure it's an honest and easy mistake but hopefully that should make it all the easier to resolve :) Let me know if you have any questions and I genuinely appreciate it!
(please note I simply want to change the display message upon clicking the button)
<script>
$(document).ready(function(){
$("#getMessage").on("click", function(){
$(".message").html("New Message");
});
});
</script>
<div id="wrapper">
<button type="button" id = "getMessage" class = "btn btn- primary">Generate New Quote</button>
</div>
<div class= "text-center">
<div class = "message">
Sample
</div>
</div>
As the others have mentioned, you are most likely not adding jQuery, yet you are attempting to use it ($). To confirm this, check your console. It's probably filled with Uncaught ReferenceError: $ is not defined.
Assuming you're using CodePen as the challenege says in the objective, you can very quickly and easily include jQuery. To do so, just click the settings cog next to JS, use the Quick-add drop down, and select jQuery.
If you wish to include it manually (as you will most likely have to in future development) I recommend Drefetr's answer.
There do not appear to be any major issues with the code (with respect to the logic, the editor may have rendered your formatting a little nastily).
Can you confirm that you have included the jQuery libraries within the header of your HTML document? e.g.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
For more information: https://developers.google.com/speed/libraries/#jquery

Loading KML into Google earth?

I can't figure out why for example I try to reproduce something basic like this example https://google-developers.appspot.com/earth/documentation/samples/fetchkml_example on my own, I can't get it to work. I'm using my key that I have been using for my Google Maps API, so I think that part should be fine, but when it comes to KML I can't seem to get it to work regardless of whether it is fetched or parsed. I have put my KML file here https://sites.google.com/site/shahinkmlexamples/experiment/kml_example.kml , and my code is below with my own key number not shown
<html>
<head>
<title>fetchkml_dom_example.html</title>
<script src="//www.google.com/jsapi?key=MYKEY#"></script>
<script type="text/javascript">
var ge;
google.load("earth", "1");
function init() {
google.earth.createInstance('map3d', initCB, failureCB);
}
function initCB(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
var href = 'https://sites.google.com/' + 'site/shahinkmlexamples/experiment/kml_example.kml';
google.earth.fetchKml(ge, href, function(kmlObject) {
if (kmlObject)
ge.getFeatures().appendChild(kmlObject);
if (kmlObject.getAbstractView() !== null)
ge.getView().setAbstractView(kmlObject.getAbstractView());
});
}
function failureCB(errorCode) {
}
google.setOnLoadCallback(init);
</script>
</head>
<body>
<div id="map3d" style="border: 1px solid silver; height: 400px; width: 600px;"></div>
</body>
</html>
so I know the solution has got to be simple, but I just can't figure it out.
Thanks
When you're loading it from a local file (such as using notepad++ and loading that file in Chrome) you need to add a protocol to the script tag:
<script src="//www.google.com/jsapi?key=MYKEY#"></script>
Becomes:
<script src="https://www.google.com/jsapi?key=MYKEY#"></script>
Without that change, your page is looking for the file in your local filesystem.
It's left out in the samples so that your browser will load the HTTPS version if your page is HTTPS, and the HTTP version if your page is HTTP. This prevents security warnings in the browser.
I'm not sure what your problem is. I put your code into an online editor - http://www.onlinehtmleditor.net/
a simple copy and paste and it worked fine.
Also, regarding the API key. For Google Earth you no longer need one. Simply use the generic javascript call below

Using <script> in CSS

Is there any way to write script in css and call or execute it whenever required ?
I need a <script> tag to be executed .
i need something like this..
css code
#execute{
<script> ..some script.. </script>
}
so whenever i use
<html>
.
.
.
.<div id="execute" />
.
.
.
.
</html>
so if i change the script changes will be reflected everywhere.
Is it possible?
EDIT:
Is it possible to keep my <script></script> tags inside some js file and i will host it. and then i will call some function() from my HTML so that the script will be executed everywhere i need it.
Can someone show me any example, tutorial how i can do it.
I don't have much information about the Js file and how the function should be called.
Thank you all
Does it have to be in CSS? jQuery is a great, simple way to do what you're asking. You put all your style information in the CSS (what it's intended for) and keep your javascript in the html or a .js file. Take a look at http://jquery.com. The code would look something like this
$(function() {
$('#execute')
.someCoolFunction()
.anotherCoolFunction();
});
You use $(function() { /* code */ }); to run the code when your document is ready, and you use $('#execute') to grab the element with the execute tag. You can then do a lot of cool javascript really easily with that jQuery element.
No, you cannot mix CSS and Javascript this way. Why would you want to?
If you simply want a common JavaScript include, do it like this:
<script type="text/javascript" src="yourscript.js"></script>
You can't do this in standard CSS.
There is a way in which you can run code from within the CSS context, using a technology called 'Behaviours', referencing an HTC file (which is basically Javascript) in the stylesheet.
However, this technology is non-standard, and only exists in IE. It is therefore only really used to write hacks to make IE support features that it doesn't have which are in other browsers. An example of this in use is CSS3Pie.
If you're working on a site which will never be used in any browser other than IE, and you're happy to use a non-standard technology, then you may consider this to be the exact answer to your question. However I would strongly recommend you don't do this.
More realistically, you should be using a Javascript library such as JQuery, as the functionality you describe is pretty much standard fare for JQuery.
With JQuery, you would write code like this (in a normal script block, not in the CSS!):
$('.execute').each(function() {
/* your code here; it would be run for each element on the page with the class of 'execute' */
}
As you can see, it uses a CSS-style selector syntax to select the elements to work with.
(also NB: I've used execute as a classname here, not as an ID, because you imply that you want more than one of them -- note that you should never use the same ID more than once in any HTML page; it is invalid. If you need the same thing several times, use a class.
JQuery has functionality to watch for changes to elements, respond to events such as clicks or mouse over, and much more. Other similar libraries such as Prototype, MooTools and Dojo would also be able to do a similar job.
Hope that helps.
[EDIT]
Given the edit to your question, can you not just place the advertisment <script> tag inside the <div> on the page where you want it?
So with JQuery, you could write something like this to run your ad in each place you want it:
HTML:
....
<div class='execute'></div>
....
<div class='execute'></div>
....
Javascript code (remember to also include the JQuery library, or this won't work):
$(document).ready(function () {
$('.execute').each(function() {
advertisement(this); //change to whatever the advertisement script function is called.
});
});
Hopefully that will get you started. I can't really help you much more without knowing more about the advertisement script, though.
Also, the people who supplied the advert script should be able to tell you how to use it.
I believe a Javascript library like JQuery or Dojo is what you are looking for. It will allow you to add event handlers on tags with certain CSS attributes, which will behave exactly like what you are trying to do right now.
EDIT
Here is an example with Dojo pulled from the Google CDN that will popup an alert window when you click on any <div class="execute"></div> block:
<html>
<head>
<style>
<!--
.execute { background-color: red; height: 25px; }
-->
</style>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js" ></script> <!-- load Dojo from Google CDN
<!-- Let's register a onClick handle for any .execute div. -->
<script>
dojo.ready(function() // Dojo will run this after being initialized
{
// Get A list of all tags with id execute and add a event onClick
dojo.query(".execute").connect("onclick", function(evt)
{
alert("Event triggered!");
// ...
});
});
</script>
</head>
<body>
<div class="execute">Click me 1</div>
<br /><br />
<div class="execute">Click me 2</div>
</body>
</html>
Edit 2
This example uses an onClick event but Dojo (JQuery) allows you to do much more things. For instance if you wanted to dynamically add an image or something onLoad inside .execute divs, you could do it with Dojo (JQuery) in a similar way to this.
Doing it with a library saves you a lot of effort, but if you still want to write and call your own functions from javascript files, this is a rough idea of how you would do it:
// myScript.js
function foo()
{
// ...
}
// page.htm
<html>
<head>
<script src="path/to/myScript.js"></script>
</head>
<!-- ... -->
<div class="execute">
<script>
<!--
// Call foo()
foo();
-->
</script>
</div>
<!-- ... -->
It doesn't really make sense to abstract a script into CSS like that, and even if it was a good idea, it can't be done.
Why do you need to run the same script over and over in different places? Consider whether or not there might be a better or simpler way to do whatever it is you're doing.
Plus, when you include a script with the src attribute in the script tag, if you modify the script's source file, the changes persist everywhere.
No, but you can use script to alter the CSS properties of any element in the DOM.