1
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>
4

2 回答 2

1

几个问题:

  • JavaScript+用于连接,而不是&
  • 属性名称区分大小写。尝试WinNetwork.UserName
  • 您正在尝试设置src不存在的框架窗口的属性。您需要设置框架 DOM 对象的 src。即window.frames返回一个 Window 对象并document.getElementById('')返回对 HTMLFrameElement 的引用
  • (来自 Teemu)您不能在同一页面上同时拥有框架集和正文标签。

代码

var urlToSite = "http://localhost/index.php?nph-psf=0&HOSTID=AD&ALIAS=" +
                 encodeURIComponent(WinNetwork.UserName);


document.getElementById("psyncLink").src = urlToSite;

参考 http://www.pctools.com/guides/scripting/detail/108/?act=reference

于 2012-06-12T16:37:40.637 回答
1

尽管不允许嵌套frameset,但对于那些不支持框架的浏览器,在“旧时代”元素之后包含在内。这在 IE9 标准模式下仍然有效,但是你看不到帧。bodybodyframeset

getWindowsUserName()在页面加载后执行,您可以执行以下操作:

   window.onload=getWindowsUserName;
</script>
</head>
<frameset cols="300,*">
   <frame src="" name="topo" ...>
   <frame src="topo1.htm" name="psyncLink" ...>
</frameset>

或者移动getWindowsUserName()到 topo1.htm。

MSDN 中的更多信息frameset

于 2012-06-12T17:29:08.150 回答