我在ie中得到了错误的URL,但在firefox和chrome中却没有。
基本上,我有一个名为text-search的文本字段。我在htaccess中使用jQuery和rewriterule来内部重定向页面。我在localhost上,所有文件都在一个名为test的文件夹中。
在火狐和chrome中,如果你在文本搜索框中输入'hello‘,按回车键,'hi’按回车键,‘再见’按回车键,你就会得到正确的网址
localhost/test/test/hello
和
localhost/test/test/hi
和
localhost/test/测试/再见
分别是。
在ie中你可以得到
localhost/test/test/hello
和
localhost/test/hi
和
localhost/test/testing/testing/testing/goodbye
分别
这里的问题是“测试”是前置的。如何阻止这种情况在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]你能帮帮我吗?非常感谢
发布于 2013-10-05 00:16:31
window.location不是一个字符串,我会非常小心地使用它-它实际上是一个Location对象。
也许这会对你有所帮助:
var href = window.location.href;
window.location = href.replace(/testing\/.*$/, "testing/"+$('#text-search').val());您还可以执行以下操作:
var href = "" + window.location;强制字符串转换,并按值传递。
发布于 2016-11-02 05:23:13
如果您像这样设置:window.location.href = '/yourpage'
它将附加url。要避免这种情况,请使用//而不是/
因此,它将如下所示:window.location.href = '//yourpage'
发布于 2019-03-27 21:17:06
考虑到url栏中的currenturl为。
我们将考虑两个案例
第一个**window.location = 'dummy-string'**
第二个**window.location = '/another-dummy-string'**
然后,在第一种情况下,它将获得附加到URL的,而在第二种情况中,它将使用替换URL中的路径名(即/marketing)。
https://stackoverflow.com/questions/19186000
复制相似问题