将变量从文本控制传递到谷歌客户搜索引擎CSE [英] Passing variable from text control to google custome search engine CSE
本文介绍了将变量从文本控制传递到谷歌客户搜索引擎CSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在索引页面中有一个textBox,我希望它将此文本中的值带到另一个页面中的Google搜索引擎。
如何将这个变量从控件传递到cse?
这是传递的索引代码变量
Hi,
I have a textBox in the index page and I want it to take the value from this text to the google search engine in another page.
how can i pass this variable from control to the cse?
This is the index code for passing the variable
Response.Redirect("Search.aspx?parma=" + TextBox1.Text);
这是cse代码
and this is cse code
<script>
(function () {
var cx = '003646811200027851123:9ubv0q_x_z0';
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>
推荐答案
您好,
请在下面找到执行此操作的代码。
Hello,
Please find below the code to do this.
<!DOCTYPE html>
<html>
<head>
<title>Element V2: Google-hosted Layout Demo</title>
<!-- Put the following javascript before the closing </head> tag. -->
<script>
(function() {
var cx = '003646811200027851123:9ubv0q_x_z0';
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>
</head>
<body>
<div>
Element V2 Google-hosted Layout Demo: open the results page in a new window
</div>
<!-- Place this tag where you want the search box to render -->
<!--
1) newWindow=true overwrites settings stored in CSE control panel.
2) Or store your settings in CSE control panel "Look and Feel" tab:
Choose where your Google-hosted results appear: "New Window" or
"Current Window".
-->
<gcse:searchbox-only newWindow=true></gcse:searchbox-only>
</body>
</html>
问候,
Regards,
我只需要这个属性
All I needed is this attribute
<gcse:search queryparametername="q" xmlns:gcse="#unknown"></gcse:search>
<script>
(function() {
var cx = 'CXXXXXXXXXXX';
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);
})();
window.onload = function(){
document.getElementById('gsc-i-id1').value = '<?=
这篇关于将变量从文本控制传递到谷歌客户搜索引擎CSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文