如何通过JavaScript导航锚标记中的href
是否有一种简单的方法可以让JavaScript模仿用户点击页面上的锚标记? 这意味着需要设置Referrer Url。 仅设置document.location.href不会设置Referrer Url。
$(document).ready(function () { $("a").click(); }); Go here
这不起作用,因为没有链接的Click()事件设置。
你可以这样做:
window.location = $("a").attr("href");
如果你想保留推荐人,你可以这样做:
var href = $('a').attr('href'); $('
这是hackish,但适用于所有浏览器。
也许这就是你想要的东西?
$(document).ready(function () { $("a").each(function(){ if($(this).click()){ document.location.href = $(this).attr("href"); } }); });
document.location.href = "#wanted_Location";
好的,referer没有使用document.location设置(根据我的其他答案),可能与window.navigate(url)一起使用? 如果这不起作用,可能会有以下情况,尽管它很丑陋 – 丑陋:
$(function() { $("a").each(function(){ if($(this).click()){ $('').appendTo("body").submit(); return false; } }); });
有一种更简单的方法来实现它,
HTML
Bootstrap is life
JavaScript的
// Simulating click after 3 seconds setTimeout(function(){ document.getElementById('fooLinkID').click(); }, 3 * 1000);
使用普通的javascript来模拟点击。
您可以在jsFiddle上查看这里的工作示例。