我如何将用户从一个页面转向另一个页面,使用jQuery或纯粹的JavaScript?
当前回答
您可以在 jQuery 中以以下方式重定向:
$(location).attr('href', 'http://yourPage.com/');
其他回答
使用 JavaScript:
方法1:
window.location.href="http://google.com";
方法2:
window.location.replace("http://google.com");
使用 jQuery:
方法1: $(位置)
$(location).attr('href', 'http://google.com');
方法2:可重新使用的功能
jQuery.fn.redirectTo = function(url){
window.location.href = url;
}
jQuery(window).redirectTo("http://google.com");
与 jQuery 合作:
$(window).attr("location", "http://google.fr");
下面是将代码转向另一个页面,时间为10秒。
<script>
function Redirect()
{
window.location="http://www.adarshkr.com";
}
document.write("You will be redirected to a new page in 10 seconds.");
setTimeout('Redirect()', 10000);
</script>
你也可以这样做,点击一个按钮使用 location.assign:
<input type="button" value="Load new document" onclick="newPage()">
<script>
function newPage() {
window.location.assign("http://www.adarshkr.com")
}
</script>
var url = 'asdf.html';
window.location.href = url;
您可以使用 jQuery 如下:
window.location = "http://yourdomain.com";
如果你只想要jQuery,那么你可以这样做:
$jq(window).attr("location","http://yourdomain.com");
推荐文章
- 在React Native中使用Fetch授权头
- 为什么我的球(物体)没有缩小/消失?
- 如何使用jQuery检测页面的滚动位置
- if(key in object)或者if(object. hasownproperty (key)
- 一元加/数字(x)和parseFloat(x)之间的区别是什么?
- angularjs中的compile函数和link函数有什么区别
- 删除绑定中添加的事件监听器
- 如何在JSON中使用杰克逊更改字段名
- 很好的初学者教程socket.io?
- HtmlSpecialChars在JavaScript中等价于什么?
- React: 'Redirect'没有从' React -router-dom'中导出
- 如何在React中使用钩子强制组件重新渲染?
- 我如何使用Jest模拟JavaScript的“窗口”对象?
- 我如何等待一个承诺完成之前返回一个函数的变量?
- 在JavaScript中根据键值查找和删除数组中的对象