function getWindowsUserName()
{
var WinNetwork = new ActiveXObject("WScript.Network");
var urlToSite = "http://localhost/index.php?nph-psf=0&HOSTID=AD&ALIAS=" + WinNetwork.UserName;
window.frames["psyncLink"].src = "http://localhost/index.php?nph-psf=0&HOSTID=AD&ALIAS=" + WinNetwork.UserName;
return;
}
我正在尝试让框架加载 urlToSite
<body onload="getWindowsUserName()">
<frameset cols="300px, *">
<frame src="topo1.htm" name="topo" id="topo" application="yes" />
<frame src="topo1.htm" name="psyncLink" id="psyncLink" application="yes" />
</frameset>
</body>
实际上,现在我得到的只是一个空白页面。如果我在 IE 中访问同一个站点并手动键入用户名(大小写不敏感),则页面会在 IE 中加载。因此我认为问题出在代码中
<html>
<head>
<title>AIDS (Automated ID System)</title>
<HTA:APPLICATION
id="frames"
border="thin"
caption="yes"
icon="http://www.google.com/favicon.ico"
showintaskbar="yes"
singleinstance="yes"
sysmenu="yes"
navigable="yes"
contextmenu="no"
innerborder="no"
scroll="auto"
scrollflat="yes"
selection="yes"
windowstate="normal" />
<script language="javascript" type="text/javascript">
function getWindowsUserName()
{
var WinNetwork = new ActiveXObject("WScript.Network");
var urlToSite = createCustomURL(WinNetwork.UserName);
document.getElementById("psyncLink").src = urlToSite;
}
function createCustomURL(userName)
{
var customURL = "http://localhost/index.php?nph-psf=0&HOSTID=AD&ALIAS=" + userName;
return customURL;
}
</script>
</head>
<body onload="getWindowsUserName()">
<frameset cols="300px, *">
<frame src="topo1.htm" name="topo" id="topo" application="yes" />
<frame src="topo1.htm" name="psyncLink" id="psyncLink" application="yes" />
</frameset>
</body>
</html>
最佳答案
虽然嵌套frameset
在 body
不允许,在“旧时代”body
元素包含在 frameset
之后对于那些不支持框架的浏览器。这在 IE9 标准模式下仍然有效,但是你看不到框架。
执行getWindowsUserName()
加载页面后,您可以执行以下操作:
window.onload=getWindowsUserName;
</script>
</head>
<frameset cols="300,*">
<frame src="" name="topo" ...>
<frame src="topo1.htm" name="psyncLink" ...>
</frameset>
或者移动getWindowsUserName()
到 topo1.htm。
更多信息 frameset
in MSDN
关于Javascript 函数没有获取 Windows 用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11000884/