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 より) フレームセットと body タグを同じページに配置することはできません。

コード

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れていませんが、フレームをサポートしていないブラウザーの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 に移動します。

MSDNの詳細情報frameset

于 2012-06-12T17:29:08.150 に答える