gpt4 book ai didi

javascript - 打开或激活选项卡时自动获取 localStorage 值

转载 作者:行者123 更新时间:2023-11-30 11:30:22 25 4
gpt4 key购买 nike

我需要在 tags.php 上设置一个 localStorage 项,并在用户切换到 index.php 时自动获取其更新值。

标签.php

$(document).on('click', '.tagdown', function() {
var a = $('#tagsup').html();
localStorage.setItem('tags', a);
});

index.php
在这里我需要这样的东西:

$(window).onfocus(function(){
console.log(localStorage.getItem('tags'));
});

但是 $(window).onfocus() - 不存在。

我尝试使用 body.onfocus 在 body-child 元素具有焦点的情况下不起作用。

任何帮助。

最佳答案

您可以使用 focus()像这样的事件:

$(function() {
$(window).focus(function() {
console.log('Window is in focus');
console.log(localStorage.getItem('tags'));
});
});

关于javascript - 打开或激活选项卡时自动获取 localStorage 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46469622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com