我得到错误的网址在ie,但不是在火狐和 chrome 。
基本上,我有一个名为text-search的文本域,我在htaccess中使用jQuery和rewriterule来内部重定向页面,我在localhost上,所有文件都在一个名为test的文件夹中。
在firefox和chrome中,如果您在文本搜索框中输入"hello"回车键、"hi"回车键和"goodbye"回车键,您将获得正确的URL
本地主机/测试/测试/hello
以及
本地主机/测试/测试/hi
以及
本地主机/测试/测试/再见
分别地。
在你得到
本地主机/测试/测试/hello
以及
本地主机/测试/测试/测试/hi
以及
本地主机/测试/测试/测试/测试/再见
分别
这里的问题是"测试"是前置的。如何阻止这种情况发生在ie。我在网上找不到这个问题的答案。
html和jquery代码
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<base href="http://localhost/test/" />
<script src="jQuery.js"></script>
<script>
$(document).ready(function(){
$("#text-search").keyup(function(e){
if (e.keyCode == 13){
window.location.replace("testing/"+$('#text-search').val());
}
})
})
</script>
</head>
<body>
<input type='text' id='text-search'>
</body>
</html>
. htaccess网站
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^testing/(.+)$ /test/testing.php?string=$1 [L]
你能帮我一下吗?非常感谢
3条答案
按热度按时间toiithl61#
如果按如下方式设置:第一个月
它将追加url。要避免这种情况,请使用
//
而不是/
因此它看起来像:
window.location.href = '//yourpage'
uttx8gqw2#
window.location
不是字符串,我会非常小心地使用它-它实际上是一个Location
对象。也许这对你有帮助:
您还可以执行以下操作:
强制字符串转换,以及按值传递。
00jrzges3#
考虑URL栏中的currenturl是www.theunusualcards.com/marketing。
我们将考虑两种情况
第一个
**window.location = 'dummy-string'**
第二个
**window.location = '/another-dummy-string'**
则在第一种情况下,它将得到附加到URL,而在第二种情况下,它将是替换URL中的路径名(即 /marketing)。