admin管理员组文章数量:1401167
I was experimenting with using a .htm file as a desktop background and i wanted to make it so it would say something like "Wele, 'username'!" where 'username' would be my username that i use to log on to my puter. I have a windows xp puter if that makes a difference. I do not have much experience with javascript, but with some searching i think i found something to use to get the username:
<script language="javascript">
function GetUserName()
{
var wshell = new ActiveXObject("WScript.Shell");
alert(wshell.ExpandEnvironmentStrings("%USERNAME%"));
}
</script>
I just found that on the web, i am not sure which part is the acquired username... What i need is to use this later in my html to display on my wallpaper: "Wele, 'username'!" I am not sure if it is needed, but i will include it anyways, the html code i want the wele statement would be in
<center><div class="widget"><div class="title"> *wele statement here* </div></div></center>
Alright thanks guys!!
I was experimenting with using a .htm file as a desktop background and i wanted to make it so it would say something like "Wele, 'username'!" where 'username' would be my username that i use to log on to my puter. I have a windows xp puter if that makes a difference. I do not have much experience with javascript, but with some searching i think i found something to use to get the username:
<script language="javascript">
function GetUserName()
{
var wshell = new ActiveXObject("WScript.Shell");
alert(wshell.ExpandEnvironmentStrings("%USERNAME%"));
}
</script>
I just found that on the web, i am not sure which part is the acquired username... What i need is to use this later in my html to display on my wallpaper: "Wele, 'username'!" I am not sure if it is needed, but i will include it anyways, the html code i want the wele statement would be in
<center><div class="widget"><div class="title"> *wele statement here* </div></div></center>
Alright thanks guys!!
Share Improve this question asked Dec 25, 2013 at 0:54 user3133613user3133613 111 gold badge1 silver badge3 bronze badges 2-
Does the
alert
work? If so, select yourtitle
element (document.querySelector(".widget .title")
, maybe? I’d give it an ID – not sure which browser engine Active Desktop uses) and put the returned value in itsinnerHTML
. (Or, better, create a text node and append it…) – Ry- ♦ Commented Dec 25, 2013 at 0:58 - 1 fyi that won't work in non-ie browsers. – Daniel A. White Commented Dec 25, 2013 at 1:07
1 Answer
Reset to default 2Give your title DIV an ID:
<center><div class="widget"><div class="title" id="wele"> Wele </div></div></center>
Then use the following Javascript:
window.addEventListener('load', function() {
var username = GetUserName();
document.getElementById('wele').innerHTML = 'Wele, '+username;
});
function GetUserName() {
var wshell = ActiveXObject && new ActiveXObject("WScript.Shell");
return wshell && wshell.ExpandEnvironmentStrings("%USERNAME%");
}
本文标签: javascriptUse windows username in htmlStack Overflow
版权声明:本文标题:javascript - Use windows username in html - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744302593a2599652.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论