从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>
.