【问题标题】:Use JavaScript to start YouTube search使用 JavaScript 启动 YouTube 搜索
【发布时间】:2014-05-07 12:04:15
【问题描述】:

我正在为服装新标签页构建一个搜索栏。目的是在多个地方进行搜索,其中一个应该是 YouTube。 我想在 YouTube 上结束,而不是使用 API 返回结果。

我有一个这样的表格:

<form id="searchForm">
    <input name="q" type="text" value="" id="searchTerm-js">
</form>

输入的名称是 q,因为默认搜索是 Google(已经可以使用)。 当您输入输入并按“返回”时,会调用一个 JavaScript 函数,该函数应该开始搜索。

    if(term.indexOf("!y ") > -1) {              //want to search youtube
        term = term.replace("!y ", "");         //take away the "command"
        form.action="http://youtube.com/result";//set URL
        $("#searchTerm-js").val(term);          //set what to search for
        $("#searchTerm-js").attr("name", "search_query"); //Change name of input
        form.method="GET";                      
        form.submit();                          //Do search
    }

现在我希望被定向到“youtube.com/result?search_query=term”,其中“term”是我要搜​​索的内容。 (成功将此应用到谷歌) 但我被定向到“youtube.com/user/result?search_query=term”?

任何想法为什么会发生这种情况以及如何使这个搜索工作?

关于 DuckDuckGo:是的,我知道 DuckDuckGo 有类似的功能,但我想添加更多网站并使用德国 Google。

【问题讨论】:

    标签: javascript jquery html youtube


    【解决方案1】:

    网址中的错字

    http://youtube.com/result

    应该是:

    http://youtube.com/results

    【讨论】:

    • 谢谢...所以上面是做我想做的事,现在工作正常。
    猜你喜欢
    • 2023-03-23
    • 2019-04-07
    • 1970-01-01
    • 2018-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-22
    相关资源
    最近更新 更多