查询网址登录状态,JavaScript的状态、网址、JavaScript

2023-09-10 18:25:19 作者:往事若梦逝流年

这似乎是一个没有脑子,但我不能找到一个方法来做到这一点,不被认为是安全问题(不是明显的方式等)

This may seem like a no-brainer, but I can't find a way to do this that isn't considered a security issue (other than the obvious ways)...

所以,我想建立一个附加的用于Firefox和我的团队使用。基本上,这将是一个状态栏图标,让我们知道,如果我们的工具网站的身份验证Cookie已过期,所以我们可以说没有当前在浏览器丢失任何工作。

So, I want to build an add-on for Firefox to use with my team. Basically it will be a status bar icon letting us know if the authentication cookie for our tools site has expired, so we can tell without losing any work currently in the browser.

起初,我以为我可以有附加检查的cookie,但是这似乎是一个巨大的麻烦,对于这样一个简单的想法。然后,它发生,我......杜......我可以只对尝试的插件来访问我们网站的主页。如果它获得了拒绝访问的响应,它可以显示为未登录图标,但如果它得到任何东西,它可以显示已登录。

At first I thought I could have the add-on check the cookie, but this seems to be a huge hassle for such a simple idea. Then it occurred to me...DUH...that I could just have the add on try to access the main page of our site. If it gets a "Access Denied" response, it can show the icon for "Not Logged In", but if it gets anything else, it can show "Signed In".

不过,所有试图使用AJAX被证明是几乎一样困难,因为我的cookie的尝试做到这一点。

However, all attempts to do this with AJAX are proving to be almost as difficult as my cookie attempts.

有没有一种简单的方法,使用javascript preferably,但在XUL否则,说了

Is there a simple way, with javascript preferably, but in XUL otherwise, to say

var url = "http://example.com";
var response = pingURL(url, "blah);
status = (response = "Welcome!") ? "Signed in" : "Not Signed In";

,其中pingURL将是走出去的网址,并得到响应的方法是什么?

where "pingURL" would be the method of "going" to the url and getting the response?

推荐答案

究竟为什么你认为饼干巨大的麻烦?这无疑将更快,可能更简单的实现。读取cookie的浏览器是简单,证据充分的。寻求帮助,如果你不能弄清楚如何解析的cookie。

Exactly why do you consider cookies a huge hassle? That would undoubtedly be faster and probably simpler to implement. Reading cookies from chrome is simple and well-documented. Ask for help if you can't figure out how to parse the cookie.