gpt4 book ai didi

javascript - 如何在 Chrome 扩展中比较变量与本地存储?

转载 作者:行者123 更新时间:2023-12-02 19:51:51 25 4
gpt4 key购买 nike

下面是我在 Chrome 扩展程序中使用的代码,它从本地存储中获取 URL 并将其与网页的当前 URL 进行比较。

问题是 javascript 没有将它们显示为相等,即使它们是相同的..(下面 a=http://www.google.com 和 b=http://www.google.com)

var a="";
chrome.extension.sendRequest({method: "getLocalStorage", key: "url"}, function(response) {
a=response.data;
});
var b = document.location;

//I am trying to compare a and b but I always get they are equal even though they are one and the same

if (a==b)
{
alert("Equal");
}

最佳答案

需要等待响应回调函数。将代码更改为:

var a="";
chrome.extension.sendRequest({method: "getLocalStorage", key: "url"}, function(response) {
a=response.data;
var b = document.location;
if (a==b)
{
alert("Equal");
}
});

关于javascript - 如何在 Chrome 扩展中比较变量与本地存储?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9207254/

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