在<a>标记在窗口加载之后()

Apply some events and actions on <a> tag after window load()

本文关键字:加载 之后 窗口 lt gt      更新时间:2023-09-26

我的页面中有一些链接,单击任何链接后,它都会转到另一个页面并加载窗口。

但我想对上次点击的链接采取一些行动,我申请了。但当窗口加载发生时,一切都消失了。

这些链接对每个页面都是通用的。

请帮帮我。很抱歉犯了错误。

谢谢。

我假设您正在尝试在导航菜单中突出显示当前页面的链接。看看这个。。。

http://docs.jquery.com/Tutorials:Auto-Selecting_Navigation

您需要通过GET或POST将变量发送到下一页

将它们保存在cookie、数据库或服务器上的文件中


假设变量是show=1page=phones


你可以发送这样的变量:

var show = 1;
var page = 'phones';
$('#link').click(function(){
  top.location.href = 'page.html?show='+show+'&=page'+phones+'';
});

然后,您可以使用PHP或ASP等服务器端语言在下一页上获取变量,也可以用javascript创建一个智能函数来获取所需的URL部分:

function getParam(name) {
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    );
}

并像这样使用它(在page.html中):

var show = getParam('show');
var page = getParam('page');

如果你想在用户浏览器中将变量保存到cookie中,你可以使用以下功能:

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^'s+|'s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

并像这样使用它们:

在你的第一页:

var show = 1;
var page = 'phones';
setCookie(''+show+'',show,5); // expire after 5 days
setCookie(''+page+'',page,5); // expire after 5 days
// now redirect to other page like in the first example
$('#link').click(function(){
  top.location.href = 'page.html';
});

在您的第二页:

var show = getCookie('show');
var page = getCookie('page');
if (show === 1) {
  // Do whatever you like, because cookie 'show' is 1
}

我希望它能有所帮助!