【问题标题】:How to remove URL Parameter when Submit on Search Engine在搜索引擎上提交时如何删除 URL 参数
【发布时间】:2014-10-06 08:29:01
【问题描述】:

我在自己的网站上构建了自己的搜索引擎。

当我单击提交(作为搜索按钮)时,我希望在 URL 处搜索的输出是:

http://inindonesia.org/marketplace/tags/oleh-oleh-khas-medan

但是,当我点击提交(搜索按钮)时,输出是:

http://inindonesia.org/marketplace/tags/?search=oleh+oleh+khas+medan&hidden=oleh-oleh-khas-medan&Submit=Cari+Produk

我的代码是:

<form autocomplete="off" action="/marketplace/tags/(i want this get parameter from the value input id "hidden", example : oleh-oleh-khas-medan)" method="GET">
    <table border="0" border="0" cellpadding="2px" cellspacing="2px" width="100%" bgcolor="">
        <tr>
            <td style="font-size:12px; text-align:left;" width="80%">
                <input id="search" name="search" type="text"/><input id="hidden" name="hidden" type="hidden"/>
            </td>
            <td style="font-size:12px; text-align:right;" width="20%">
                <input id="searchsubmit" name="Submit" value="Cari Produk" type="submit">

仅供参考:我在我的网站上使用 Wordpress。

有什么想法可以改变我想要的 url 参数吗?
谢谢

【问题讨论】:

  • 要获得准确描述的行为,您需要将方法更改为POST,添加一个onsubmit 处理程序,将input 的值附加到action url,然后重新- 提交表单数据(或在 onsubmit 事件中使用window.location.href = http://inindonesia.org/marketplace/tags/ + input valuereturn false;

标签: php mysql wordpress search-engine url-parameters


【解决方案1】:

试试这样的......或者你想要一些不同的东西?解释一下?

HTML

<form autocomplete="off" action="" onsubmit="return submitform()" method="POST">
    <table border="0" border="0" cellpadding="2px" cellspacing="2px" width="100%" bgcolor="">
        <tr>
            <td style="font-size:12px; text-align:left;" width="80%">
                <input id="search" name="search" type="text"/><input id="hidden" name="hidden" type="hidden"/>
            </td>
            <td style="font-size:12px; text-align:right;" width="20%">
                <input id="searchsubmit" name="Submit" value="Cari Produk" type="submit">
        </td>
        </tr>
        </table>
</form>

JAVASCRIPT

<script type="text/javascript">
function submitform()
{
    var hiddenFieldValue    =   document.getElementById('search').value;
        hiddenFieldValue    =   hiddenFieldValue.replace(/\s+/g, '-').toLowerCase();
        //alert(location.host+'/marketplace/tags/'+hiddenFieldValue);
        window.location         =   'http://'+location.host+'/marketplace/tags/'+hiddenFieldValue;
}
</script>

【讨论】:

  • 非常感谢@Zeeshan.. 但是为什么它仍然重定向到我的位置主机?你可以在我的网站上查看:www.inindonesia.org.. 我已经在我的脚本中添加了 submitform() 函数.. 可能是因为我使用了 wordpress?请指教,谢谢..
  • @MimmaRuchaini 我已经测试了它的工作正常,你到底遇到了什么问题,它的重定向很好,到搜索的关键字位置,就像我搜索测试 abc,它把我重定向到 inindonesia.org/marketplace/tags/test-abc,您可以使用此行进行检查。从控制台(window.location = 'http://'+location.host+'/marketplace/tags/test-abc')
  • yes.. 它工作正常,因为它适用于 keydown 功能......您可以尝试 1. 输入任何内容,2. 当自动完成出现时单击您想要的任何内容,3. 然后单击“Cari Product”按钮.. 它显示带有正确 url 的警报,但是当我在警报上单击确定时,它会重定向到 inindonesia.org,显示混乱.. 换句话说,我自己的搜索引擎中有 2 个功能.. 1. 当 keydown 功能, 2. 当点击 'Cari Product' 功能然后重定向.. 谢谢@Zeeshan :)
猜你喜欢
  • 1970-01-01
  • 2017-03-08
  • 1970-01-01
  • 1970-01-01
  • 2017-07-07
  • 1970-01-01
  • 1970-01-01
  • 2010-10-06
  • 2018-05-12
相关资源
最近更新 更多