使用jQuery或纯 JavaScript 如何将用户从一页转到另一页?
当前回答
在单击功能上,只需添加:
window.location.href = "The URL where you want to redirect";
$('#id').click(function(){
window.location.href = "http://www.google.com";
});
其他回答
var url = 'asdf.html';
window.location.href = url;
您可以在没有jQuery 的情况下这样做 :
window.location = "http://yourdomain.com";
如果你只想要jQuery, 你可以做它喜欢:
$jq(window).attr("location","http://yourdomain.com");
这样做有三个主要途径,
window.location.href='blaah.com';
window.location.assign('blaah.com');
还有...
window.location.replace('blaah.com');
最后一个是最好的, 用于传统的重定向, 因为它不会保存您在搜索历史中被重定向之前的页面。 但是, 如果您只想用 JavaScript 打开一个标签, 您可以使用上述任何选项 。1
爱迪特:window
前缀是可选的 。
使用location.replace()
这将调整您的方向, 但不保存上一页的历史。 提交表格时最好使用此选项 。
但当你想保留自己的历史时,你必须使用location.href=//path
.
实例:
// Form with steps
document.getElementById('#next').onclick = function() {
window.location.href='/step2' // Iteration of steps;
}
// Go to next step
document.getElementById('#back').onclick = function() {
window.history.back();
}
// Finish
document.getElementById('#finish').onclick = function() {
window.location.href = '/success';
}
// On success page
window.onload = function() {
setTimeout(function() {
window.location.replace('/home'); // I can't go back to success page by pressing the back button
},3000);
}
我已经使用 JavaScript 的函数重定向() 。 它正在工作 。
<script type="text/javascript">
$(function () {
//It's similar to HTTP redirect
window.location.replace("http://www.Technomark.in");
//It's similar to clicking on a link
window.location.href = "Http://www.Technomark.in";
})
</script>
推荐文章
- AngularJS:工厂和服务?
- js:将一个组件包装成另一个组件
- 登录后,Laravel重定向回原始目的地
- 父ng-repeat从子ng-repeat的访问索引
- JSHint和jQuery: '$'没有定义
- 模仿JavaScript中的集合?
- 用JavaScript验证电话号码
- 如何在HTML5中改变视频的播放速度?
- 谷歌地图API v3:我可以setZoom后fitBounds?
- 用jQuery检查Internet连接是否存在?
- 如何使用滑动(或显示)函数在一个表行?
- ES6/2015中的null安全属性访问(和条件赋值)
- 与push()相反;
- JS字符串“+”vs concat方法
- AngularJS使用ng-class切换类