Custom search engine for Google not working - google-custom-search

I am trying to integrate custom search engine of google but to no avail. Every time it returns 'No Result' for every data passed.
Code:
<script>
(function() {
var cx = '009439376788807650262:rd6prt0twra';
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>
<gcse:search resultsUrl="http://amniltech.com.np/investment/" newWindow="true" queryParameterName="search">
</gcse:search>
</div>
Can anyone help me here? What am I doing wrong? I am using fuelphp.

<script>
(function() {
var cx = 'Your_Cx_iD';
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>
<gcse:search resultsUrl="http://www.amniltech.com.np/investment/" newWindow="true" queryParameterName="search">
This will work.

Related

Can you pretty print IHtmlContent?

If I have a IHtmlContent can I pretty print it?
Example:
var html = new HtmlString("<article><h2>Hello!</h2></article>");
I want it pretty printed with line breaks and indention into:
<article>
<h2>Hello!</h2>
</article>
I do not want:
<article><h2>Hello!</h2></article>
You could try to JavaScript to add the line breaks and indention into, then, use <pre> tag to render the html content. Please check the following sample:
Index.cshtml:
#{
var html ="<article><h2>Hello!</h2></article>";
}
<div id="printdiv">
#Html.Raw(html)
</div>
<div id="output">
</div>
<input type='button' id='btn' value='Print' onclick='printDiv();'>
#section Scripts{
<script>
function printDiv() {
var divToPrint = document.getElementById('printdiv');
//display the pretty html content in the web page.
document.getElementById("output").innerHTML = "<pre>" + process(divToPrint.innerHTML).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">") + "</pre>";
//create a new window to print the div content.
var newWin = window.open('', 'Print-Window');
newWin.document.open();
newWin.document.write('<html><body onload="window.print()"><pre>' + process(divToPrint.innerHTML).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">") + '</pre></body></html>');
newWin.document.close();
setTimeout(function () { newWin.close(); }, 10);
}
function process(str) {
var div = document.createElement('div');
div.innerHTML = str.trim();
return format(div, 0).innerHTML;
}
function format(node, level) {
var indentBefore = new Array(level++ + 1).join(' '),
indentAfter = new Array(level - 1).join(' '),
textNode;
for (var i = 0; i < node.children.length; i++) {
textNode = document.createTextNode('\n' + indentBefore);
node.insertBefore(textNode, node.children[i]);
format(node.children[i], level);
if (node.lastElementChild == node.children[i]) {
textNode = document.createTextNode('\n' + indentAfter);
node.appendChild(textNode);
}
}
return node;
}
</script>
}
The result like this:
You can parse it XML with XDocument.Parse then use XmlWriter with its settings set to Indent to true. Worked for me on my HTML too.
var html = new HtmlString("<article><h2>Hello!</h2></article>");
using var writer = new StringWriter();
html.WriteTo(writer, HtmlEncoder.Default);
var htmlString = writer.ToString();
var settings = new XmlWriterSettings
{
OmitXmlDeclaration = true,
Encoding = Encoding.UTF8,
Indent = true,
};
var sb = new StringBuilder();
using (var writer = XmlWriter.Create(sb, settings))
{
XDocument.Parse(htmlString).Save(writer);
}
Console.WriteLine(sb.ToString());

Why XMLHttpRequest is not working on Edge?

I'm trying to do an application using HTML, PHP & JavaScript, I have this function that works fine on Chrome, but not working on Edge. Can someone help me, please? Thanks in advance
function GetArduinoInputs(ip, sinc)
{
nocache = "&nocache=" + Math.random() * 1000000;
var request = new XMLHttpRequest();
var dataReq = [0, 0, 0];
request.onreadystatechange = function()
{
if (this.readyState == 4) {
if (this.status == 200) {
if (this.responseXML != null && sinc == true) {
// extract XML data from XML file
document.getElementById("input1").innerHTML =
this.responseXML.getElementsByTagName('freeChlorine')[0].childNodes[0].nodeValue;
document.getElementById("input2").innerHTML =
this.responseXML.getElementsByTagName('pH')[0].childNodes[0].nodeValue;
document.getElementById("input3").innerHTML =
this.responseXML.getElementsByTagName('temperature')[0].childNodes[0].nodeValue;
document.getElementById("input4").innerHTML =
this.responseXML.getElementsByTagName('poolName')[0].childNodes[0].nodeValue;
document.getElementById("input4").style.color = "blue";
}
if (this.responseXML != null && sinc == false) {
dataReq[0] = this.responseXML.getElementsByTagName('freeChlorine')[0].childNodes[0].nodeValue;
dataReq[1] = this.responseXML.getElementsByTagName('pH')[0].childNodes[0].nodeValue;
dataReq[2] = this.responseXML.getElementsByTagName('temperature')[0].childNodes[0].nodeValue;
}
} else {
document.getElementById("input1").innerHTML = "...";
document.getElementById("input2").innerHTML = "...";
document.getElementById("input3").innerHTML = "...";
document.getElementById("input4").innerHTML = "Erro de ligação";
document.getElementById("input4").style.color = "red";
}
}
}
request.open("GET", ip + nocache, sinc);
request.send(null);
request.onerror = err => alert('Error:' + err.message);
setTimeout(function(){ GetArduinoInputs(ip, sinc); }, 1000);
return dataReq;
}
It works on this version: Versão 81.0.416.68

Exclude FTP results from Google custom Search

I did get my code to implement google custom search which is below:
<script>
(function() {
var cx = '007573243353096205708:4ydbnopnt9s';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:search></gcse:search>
But this code and my public url shows me FTP results.
When I try to exclude ftp results like ftp://www.mysite.com/*
it excludes all results.
What should I do so that my search excludes FTP results.
I saw this link but could not understand where to put the code suggested
https://productforums.google.com/forum/#!searchin/customsearch/ftp%7Csort:relevance/customsearch/CitHAOTAgS4/W79di_lOuS8J
Any help is appreciated.

Google custom search engine with bootstrap design

I would like to ask how I can combine Google CSE with Bootstrap. I found some answers on the internet but how i guess it is not actual. Because the code which I get from google looks really differently.
What I get from google:
<script>
(function() {
var cx = '001723502654893543491:ljrinx1fco0';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:search></gcse:search>
So, what I need to do is turn off the default design which is define ... uhm... I have no idea where. And set (somehow) classes of objects (textbox, button, search results ,... ) on classes from bootstrap css.

Localizing the sign-in button

hallo following this tutorial
https://developers.google.com/+/web/signin/#customizing_the_sign-in_button
when i implement the localization script to show the button in korean, german or whatever the g+ button dissapear
<script type="text/javascript">
// Specify the language code prior to loading the JavaScript API
window.___gcfg = {
lang: 'ko'
}
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js?onload=onLoadCallback';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
Maybe im doing something wrong but the code looks so easy...
thank you for your time and sorry for my english.
You're in luck, Ian Barber just wrote a blog post about localizing Google+:
http://www.riskcompletefailure.com/2013/08/google-sign-in-localisation.html
That should answer your question.
The issue in the code is that you are missing a semicolon after the global window config markup:
<script type="text/javascript">
// Specify the language code prior to loading the JavaScript API
window.___gcfg = {
lang: 'ko'
};
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js?onload=onLoadCallback';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
Should work.