Unable to stop signin with google-plus - javascript

I am using below script to get user authenticated via google, it works fine but the problem is, with out click on g+ signin button it taks the google session from browser and authenticates the user. how to make it on buttion click.
(function() {
var po = document.createElement('script');
po.type = 'text/javascript'; po.async = true;
po.src = 'https://plus.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
Is there any way to run this function on button click.?

I prefer to use Google Javascript Api.
<a id="googleLogin"> Login with Google</a>
<script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></>
<script type="text/javascript">
$(document).ready(function(){
$("#googleLogin").bind("click", function(){
gapi.auth.authorize({client_id: YOUR_CONSUMER_KEY,
immediate: false,
scope: "https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email"
}, function(authResult){
YOUR CODE HERE
});
});
});
</script>

HTML
<input id="authBtn" type="button" value="authenticate me"/>
JS
document.getElementById("authBtn").addEventListener("click", function(e) {
var po = document.createElement('script');
po.type = 'text/javascript'; po.async = true;
po.src = 'https://plus.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
});

Related

In BigCommerce, Where do I place the Lucky Orange Email Implementation Code?

I am using the BigCommerce cornerstone theme.
Where do I place the Lucky Orange Email Implementation Code?
I placed the code in the "Footer Scripts." But this didn't work.
The code from Lucky Orange is below.
<script type='text/javascript'>
window.__lo_site_id = 120178;
(function() {
var wa = document.createElement('script'); wa.type = 'text/javascript';
wa.async = true;
wa.src = 'https://d10lpsik1i8c69.cloudfront.net/w.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wa, s);
})();
</script>

How do I utilize this tracking code with a button rather than a 'Thank You' page?

They've given me the following code to add to a 'Thank you' page; we don't have one so I'm looking to add it to the form submit button. Anyway here it is, more or less:
<script type="text/javascript">
//Unique IDs here
(function() {
var ct = document.createElement('script'); ct.type = 'text/javascript'; ct.async = true;
ct.src = capterra_prefix + '/capterra_tracker.js?vid=' + capterra_vid + '&vkey=' + capterra_vkey;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ct, s);
})();
</script>
I haven't really done any JS, so I'm not sure what's going on with their snippet, but i was hoping to just do something like..
(function GIVEITANAME() {
var ct = document.createElement('script'); ct.type = 'text/javascript'; ct.async = true;
ct.src = capterra_prefix + '/capterra_tracker.js?vid=' + capterra_vid + '&vkey=' + capterra_vkey;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ct, s);
})();
</script>
<input alt="button" name="submit" type="submit" id="test" value="click me"/ onclick="GIVEITANAME();>
Any suggestions?
Thanks!
Do it like this. having () at the end of the function declaration will invoked it meaning it will fire when loaded.
capterra_prefix,capterra_prefix,capterra_vid,capterra_vkey - you need to pass them to your function to prevent the reference error or define them inside the function via var or let.
function GIVEITANAME(capterra_prefix,capterra_vid,capterra_vkey) {
var ct = document.createElement('script'); ct.type = 'text/javascript'; ct.async = true;
ct.src = capterra_prefix + '/capterra_tracker.js?vid=' + capterra_vid + '&vkey=' + capterra_vkey;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ct, s);
};
<input alt="button" name="submit" type="submit" id="test" value="click me" onclick="GIVEITANAME('test','test','test')">

Google Custom Search Engine - control results on click

Im facing an issue with my project, I want to control the search results, which means when a user clicks on any result, there will be an action.
I am using "Google Custom Search Engine", to display search result.
This is the search box and result code:
<html>
<head>
<script>
(function() {
var cx = '000752459719902753414:o5xzy3na1va';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
</head>
<body>
<div >
<gcse:search></gcse:search>
</div>
</body>
</html>
The results displays in this line <gcse:search></gcse:search>
I'm trying to figure out how can I control each result separately on click
thanks in advance..

Google+ +1 button doesn't count

I have a Google+ +1 button and seems to work fine since I can see the +1 in a Google search. The problem is that the count box doesn't keep the number of +1.
Am I doing something wrong? You can see on http://itransformer.es
I've added the next html tag:
<div class="g-plusone" style="display: clear" data-width="200" data-href="http://itransformer.es"></div>
and the next Javascript snippet code:
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/platform.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
Well, I've found the issue. I was using http://itransformer.es URL, while I had to use http://www.itransformer.es. Now the +1's are shown.

Is it possible to insert in-line javascript code into another javascript/jquery code?

This question looks a little dumb... but I am wondering if is it possible to insert in-line javascript code into another javascript code. Lets put this clear:
I'm trying to put a google plus button, appending it through jquery as follows:
jQuery('.gplus').append('<g:plusone annotation="inline"></g:plusone>');
This button needs external js in order to work properly. What i'm trying to do is insert the external js doing this:
var gplusjs = '
<script type="text/javascript">
(function() {var po = document.createElement("script");
po.type = "text/javascript"; po.async = true;
po.src = "https://apis.google.com/js/plusone.js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(po, s);
})();
</script>';
jQuery('#js').append(gplusjs);
The result of this is the code printed as HTML, but not interpreted as a script.
This is possible? I am a dumbass? Thanks!
That's because jQuery append and scripts don't work. Do it the old fashioned way
var gplusjs = '(function() {var po = document.createElement("script");po.type = "text/javascript"; po.async = true;po.src = "https://apis.google.com/js/plusone.js";var s = document.getElementsByTagName("script")[0];s.parentNode.insertBefore(po, s);})();';
var script = document.createElement("script");
script.textContent = gplusjs;
document.head.appendChild(script);
Also note that multi line string literals don't exist in JS.
You should just execute that code normally:
var po = document.createElement("script");
po.type = "text/javascript"; po.async = true;
po.src = "https://apis.google.com/js/plusone.js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(po, s);
Or, even easier:
$.getScript("https://apis.google.com/js/plusone.js");

Categories

Resources