I am using the Google Custom Search in my web page and want to filter the results before displaying the results. I cannot find any callback in Google's documenation where I can access the results so I can tweek them before displaying the results. Below is my code in my web page.
<script>
(function() {
var cx = '99999999999999999999:ddddddddd';
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>
<div style="font-size: 1.3em">
<gcse:searchbox gname="search"></gcse:searchbox>
<gcse:searchresults gname="search"></gcse:searchresults>
</div>
Does anyone know how I can access the results before they are displayed in the searchresults element?
Custom Search has an API which allows you to retrieve the results in JSON or XML format. You'll probably want to use the official JavaScript client library to access the API more conveniently.
Related
I am trying to disable my live chat from displaying by blocking countries India and Pakistan.
I used the tool from http://www.geoplugin.com and it worked great. However - I was using the typical http javascript. I just bought the SSL version from them so that there wouldn't be a conflict with my current website which uses HTTPS and the new javascript.
However - now that I use it - I get the error message
Uncaught ReferenceError: geoplugin_countryCode is not defined
My website is https://www.blueskychat.com
The code is as follows:
<script language="JavaScript" src="https://ssl.geoplugin.net/json.gp?k=..." type="text/javascript"></script>
<script type="text/javascript">
var countryCode = geoplugin_countryCode();
if (countryCode != 'IN' && countryCode != 'PK') {
window.__lc = window.__lc || {};
window.__lc.license = 8653536;
window.__lc.chat_between_groups = false;
window.__lc.ga_version = "ga";
(function() {
var lc = document.createElement('script');
lc.type = 'text/javascript';
lc.async = true;
lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc.com/tracking.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(lc, s);
})();
}
</script>
Any ideas as to what is the problem and how to resolve?
Thanks!!
You're loading json response, but attempting to use javascript method.
Just replace json.gp with javascript.gp in your src attribute of loading script and it will work.
I'm developing an angularjs app where Google login is one of it's features.
I'm using this link to implement the feature
https://blog.codecentric.de/en/2014/06/angularjs-google-sign-integration/.
Here is also the script called when the page is loaded
`
<script type="text/javascript">
(function () {
var p = document.createElement('script');
p.type = 'text/javascript';
p.async = true;
p.src = 'https://apis.google.com/js/platform.js?onload=onLoadCallback';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(p, s);
})();
</script>
`
Is this the right way and how I can fetch data from google and show the data to the user and if he is happy to press sign up and then to be signed. I already have my app created into the google api service and tried many options but no success so far.
Thanks in advice.
Well this has a problem you would be login in directly with out being clicked so that might be a problem in future
Try something like this
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client.js?onload=onLoadCallback';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
In the view
function login()
{
var myParams = {
'clientid' : 'YOUR_CLIENT_ID.apps.googleusercontent.com', //You need to set client id
'cookiepolicy' : 'single_host_origin',
'callback' : 'loginCallback', //callback function
'approvalprompt':'force',
'scope' : 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read'
};
gapi.auth.signIn(myParams);
}
Convert this codes to Angular .
Please see this question for details
I have developed a small site for a client and the site has been placed inside a <iframe> at the clients site. The GA-script I'm using looks like this:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(
['_setAccount', 'UA-XXXXXXXX-2'], //My company's GA-account
['_trackPageview'],
['b._setAccount', 'UA-XXXXXXXX-1'], // Test GA-account
['b._trackPageview'],
['th._setAccount', 'UA-XXXXXXX-3'],
['th._setDomainName', '.clientdomain.se'], // Client GA-account
['th._trackPageview']
);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
As you can see I report the GA pageviews to the client as well. The GA script is tracking visitors and pageviews at both ends. But the problem is that on my clients side the visitor-count is more than double what they are on my end (20 000 vs 5 000). At first I thought that it was being duplicated at some point but when I checked my Crazy-Egg account I saw that it had tracked over 10 000 visits and then stopped tracking because that was my limit on the account.
The page my site is on is on a IP-address (http://XXX.XXX.XX.X/campaign/) and not on a "valid url". Could that be an issue why some of the visitors isn't beeing tracked?
Thanks in advance
I am making a small project that will let:
different websites to load my external javascript file: something like this:
<script type="text/javascript">
var vsid = "SA89696";
(function() {
var vsjs = document.createElement('script'); vsjs.type = 'text/javascript'; vsjs.async = true; vsjs.setAttribute('defer', 'defer');
vsjs.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'example.com/robot/robot.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(vsjs, s);
})();
</script>
now I want to use jquery in my javascript file, I dont have problem to load it by myself,
but I dont want to cause errors to the curresnt website if it already loaded jquery.
do you have any suggestions how to load jquery with no overrides.
You need something like this:
<script>
if(!window.jQuery)
{
var script = document.createElement('script');
script.type = "text/javascript";
script.src = "path/to/jQuery";
document.getElementsByTagName('head')[0].appendChild(script);
}
</script>
It checks if jQuery is loaded or no..
Source
I have a domain, lets call it myhost.com and i have a script addGAcode.js on myhost.com. The code contains function includeGA() that calls the standard GA code for a account set for my client domain. It looks like this:
function includeGA() {
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-432432432-43']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();
}
includeGA();
Lets call this domain groceryinbelfast.com.
Now i add to meta of groceryofbelfast script tag to include the myhost.com/addGAcode.js. Unfortunately GA does not work. The GA code is loaded properly but i suppose because it's located on other domain that the domain groceryofbelfast it cannot set cookies on groceryofbelfast domain that are necessary for statistics to work.
The point of my concept is to have GA script on my server so that when Google will change something in it or i will want to make some adjustments to it i dont need to call every time the webmaster of my client to make appropriate changes.
Any ideas?
Your includeGA() function probably won't work because _gaq needs to be declared as a global variable, not a local variable inside your includeGA() function.
You can fix that particular issue by changing to this:
function includeGA() {
window._gaq = window._gaq || [];
_gaq.push(['_setAccount', 'UA-432432432-43']);
_gaq.push(['_trackPageview']);
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
}