最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Get the HTTP Basic Auth username from javascript? - Stack Overflow

programmeradmin5浏览0评论

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"

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"

Share Improve this question asked Aug 11, 2010 at 15:56 AmandasaurusAmandasaurus 60.7k74 gold badges193 silver badges255 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 15

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:window.alert(document.location) seems to give a URL with a username (but no password). This may not be true in other browsers.

发布评论

评论列表(0)

  1. 暂无评论