没有警告页面不是通过jquery重定向
without alert page is not redirecting via jquery
我想重定向我的页面到url,这是在我的变量,但它不工作没有警报。
如果我输入alert,它会重定向,否则不会。
$(document).ready(function(){
$("a").click(function(){
var newurl = 'http://www.xyz.com/' + $(this).attr('href');
//$(this).attr(newurl,'href');
window.location.href = newurl;
alert(newurl);
});
});
thanx in advance
锚标记
<a href="includes/footer.jsp">new url</a>
试试下面的
$(document).ready(function () {
$("a").click(function (event) {
var newurl = 'http://www.xyz.com/' + $(this).attr('href');
window.location.href = newurl;
event.preventDefault()
});
});
您需要使用preventDefault()
来阻止默认事件的传播。浏览器重定向到href
之前,jquery有机会改变它。通过使用警告,您延迟了浏览器重定向,因此它看起来有效。
将preventDefault
添加到事件处理程序中,以防止在链接中跟踪URL:
$(document).ready(function(){
$("a").click(function(e){
e.preventDefault();
var newurl = 'http://www.xyz.com/' + $(this).attr("href");
window.location.href = newurl;
});
});
相关文章:
- 通过JQuery重定向到另一个页面
- Javascript/jQuery重定向到页面
- 如何使用 JavaScript 或 Jquery 重定向页面
- 带有post值的JS jQuery重定向,不带<表单>
- php表单中的JQuery-重定向到成功页面
- 使用 jQuery 重定向 youtube 视频
- 在 POST 后使用 Location 标头和 jQuery 重定向
- 使用 jQuery 重定向复选框
- 带有动画的 JQuery 重定向
- 使用 Javascript/jQuery 重定向时将 POST 数据发送到顶级 iframe
- jQuery 重定向不适用于 Rails 每个循环
- 通过 js/jquery 重定向 url 函数传递 php 变量
- 通过 jQuery 重定向
- 超链接没有't使用jQuery重定向用户
- php登录后Jquery重定向
- 从rails4中的jquery重定向到
- 会话变量在 JQuery 重定向后为空
- jQuery重定向基于两个下拉菜单
- Jquery重定向而不丢失ajax历史记录
- 我如何用Javascript或jQuery重定向我的网页??Javascript重定向