Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过javascript函数预定义google搜索_Javascript - Fatal编程技术网

通过javascript函数预定义google搜索

通过javascript函数预定义google搜索,javascript,Javascript,我需要通过一个javascript函数进行预定义的Google搜索,该函数由页面中的一个按钮启动 所以我以前试过,但没有成功: <html> <head> <script language="JavaScript"> function googleSearch(quest){ var googlefind = "http://www.google.com/search?hl=en&q=" + quest + " buy Blu-Ra

我需要通过一个javascript函数进行预定义的Google搜索,该函数由页面中的一个按钮启动

所以我以前试过,但没有成功:

<html>
<head>
<script language="JavaScript">     
  function googleSearch(quest){
   var googlefind = "http://www.google.com/search?hl=en&q=" + quest + " buy Blu-Ray DVD";
   window.open(googlefind);
  }
</script>
</head>

<body>
 <INPUT type="button" value="Buy this Anime Now!" onclick="googleSearch("Fullmetal Alchemist Brotherhood");">
</body>
</html>

谷歌搜索功能(quest){
var googlefind=”http://www.google.com/search?hl=en&q=“+quest+”购买蓝光DVD“;
打开(谷歌搜索);
}
有人能帮我吗?

在你的函数中将
escape()
添加到
googlefind
,并在你的
onclick
中将关键字改为单引号

<html>
<head>
<script language="JavaScript">
 function googleSearch(quest){
  var googlefind = quest + " buy Blu-Ray DVD";
  window.open("http://www.google.com/search?hl=en&q=" + escape(googlefind));
 }
</script>
</head>

<body>
 <INPUT type="button" value="Buy this Anime Now!" onclick="googleSearch('Fullmetal Alchemist Brotherhood');">
</body>
</html>

谷歌搜索功能(quest){
var googlefind=quest+“购买蓝光DVD”;
窗口打开(“http://www.google.com/search?hl=en&q=“+逃逸(谷歌搜索));
}

另外,请记住,某些浏览器不喜欢当前定义的
脚本标记方式。我将更改为
type='text/javascript
,而不是
language='javascript'
,如下所示:

<html>
<head>
<script type="text/javascript">
 function googleSearch(quest){
  var googlefind = quest + " buy Blu-Ray DVD";
  window.open("http://www.google.com/search?hl=en&q=" + googlefind);
 }
</script>
</head>

<body>
 <INPUT type="button" value="Buy this Anime Now!" onclick="googleSearch('Fullmetal Alchemist Brotherhood');" />
</body>
</html>

谷歌搜索功能(quest){
var googlefind=quest+“购买蓝光DVD”;
窗口打开(“http://www.google.com/search?hl=en&q=“+谷歌搜索);
}

将传递参数中的双引号替换为单引号
onclick=“googleSearch(‘全金属炼金术士兄弟会’)

太棒了,你做到了!谢谢你的帮助!