从javascript获取HTTP Basic Auth用户名? [英] Get the HTTP Basic Auth username from javascript?

查看:149
本文介绍了从javascript获取HTTP Basic Auth用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个只能通过http basic auth访问的网页。如何在该页面的javascript中找出基本的auth用户名。即当有人访问它(登录后)时,我想制作一个弹出窗口,上面写着您好,您目前是以用户$ USERNAME身份登录

I have a webpage that is only accessible over http basic auth. How can I figure out the basic auth username in javascript in that page. i.e. when someone visits it (after logging in), I want to make a popup that says "Hello, you're currently signed in as the user $USERNAME"

推荐答案

纯粹来自JavaScript是不可能的。您必须让服务器端脚本从请求中获取用户名,并将其插入生成的页面代码中以供脚本选取。 (例如,< script type =text / javascript> var username = (在此处插入JSON编码的字符串);< / script> ;

It's not possible purely from JavaScript. You'd have to have the server side script pick up the username from the request, and insert it in the generated page code for the script to pick up. (eg. <script type="text/javascript">var username=(insert JSON-encoded string here);</script>.

这篇关于从javascript获取HTTP Basic Auth用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆