简体   繁体   English

ActiveX远程桌面连接HTML对象无法使用javascript正确显示

[英]ActiveX Remote Desktop Connection HTML object not displaying correctly with javascript

I have a web app that uses the old MS remote desktop ActiveX object to connect to one of our servers. 我有一个Web应用程序,它使用旧的MS远程桌面ActiveX对象连接到我们的服务器之一。

Originally, the code was in VBScript, as that was the sample given on the MS site. 最初,代码使用VBScript,因为这是MS网站上提供的示例。 However, MS has dropped support for VBScript in IE 11, so I'm trying to change it to work with Javascript. 但是,MS已在IE 11中放弃了对VBScript的支持,因此我试图将其更改为与Javascript一起使用。 Operationally, it's working for the most part. 从操作上讲,它在很大程度上起作用。 I can connect to the server. 我可以连接到服务器。 However, the view of the server is appearing as a small square in the middle of the page. 但是,服务器的视图在页面中间显示为一个小方块。 The height and width of the control are being set, and it appears they are correct, as I can see the control's outline on the page at the size I want it. 正在设置控件的高度和宽度,并且看起来它们是正确的,因为我可以在页面上看到所需尺寸的控件轮廓。 But the view itself is very small (this doesn't happen in the VBScript version of the page). 但是视图本身很小(在页面的VBScript版本中不会发生这种情况)。 In addition, the "disconnected" event doesn't seem to fire now that I've converted the code to javascript. 此外,由于将代码转换为javascript,“断开连接”事件似乎并未触发。 Has anyone ever been able to get this component working using Javascript? 有没有人能够使用Javascript使此组件正常工作? Are there any alternatives out there that don't require any installation on the server or the client? 是否有不需要在服务器或客户端上进行任何安装的替代方案?

Okay, a little update for anyone else who might have this happen, AND another problem. 好的,对可能发生这种情况的其他人进行一些更新,这是另一个问题。 I finally got this all working with the following HTML and JS: 我终于在以下HTML和JS上完成了全部工作:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="./scripts/jquery-1.10.2.js" ></script>
</head>
<body>
<script type="text/javascript" for="rdpClient" event="OnDisconnected(reason)">
    OnDisconnected(reason);
</script> 

<script type="text/javascript">
    var pw;

    function GetPassword() {
        return $.ajax({
            url: "OpenNewRDP.aspx/GetPassword",
            type: "POST",
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            data: ''
        });
    }

    GetPassword().done(function (data) {
        pw = data.d;
        var rdpClient = document.getElementById("rdpClient");
        rdpClient.AdvancedSettings2.ClearTextPassword = pw;
    });

    function OnReadyStateChange() {
        var rdpClient = document.getElementById("rdpClient");
        if (rdpClient != undefined) {
            if ((rdpClient.readyState == 4) && (rdpClient.SecuredSettingsEnabled)) {
                SetRdpDefaultSettings();
            } else {
                rdpClient.Server = "";
                alert("Trusted Sites Error");
            }
        }
    }

    function SetRdpDefaultSettings() {
        var rdpClient = document.getElementById("rdpClient");
        var resHeight = screen.height;
        var resWidth = screen.width;
        rdpClient.DesktopHeight = resHeight - 100;
        rdpClient.DesktopWidth = resWidth - 30;
        rdpClient.height = resHeight - 100;
        rdpClient.width = resWidth - 30;
        rdpClient.UserName = "<%=UserName%>";
        //rdpClient.AdvancedSettings2.ClearTextPassword = pw;
        if (rdpClient.SecuredSettingsEnabled) {
            rdpClient.SecuredSettings.StartProgram = "<%=StartProgram%>";
            rdpClient.SecuredSettings.WorkDir = "c:\\";
        } else {
            alert("Trusted Sites settings need to be updated.");
        }
    }

    function OnDisconnected(disconnectCode) {
        window.close();
    }

</script>

<object 
    id='rdpClient'
    onreadystatechange="OnReadyStateChange()"
    codeBase='/wpresources/downloads/msrdp.cab#version=5.2.3790.0' 
    classid='CLSID:7584c670-2274-4efb-b00b-d6aaba6d3850'
    VIEWASTEXT>
    <PARAM NAME='Server' VALUE='<%=ServerName%>'>
    <PARAM NAME='StartConnected' VALUE='1'>
</object>

</body>
</html>

HOWEVER, I wanted to make sure this still worked in older versions of IE as well, since we have a bunch of clients that for one reason or another are still using IE 7 or 8 and just can't/won't upgrade. 但是,我想确保它在旧版本的IE中也能正常运行,因为我们有许多出于某种原因仍在使用IE 7或8且无法升级的客户端。 So I put the following line in the header to simulate older versions: 因此,我将以下行放在标题中以模拟旧版本:

<meta http-equiv="X-UA-Compatible" content="IE=7"/>

and I discovered that it doesn't work in IE 7 or 8 (but works fine in 9, 10, and 11). 我发现它在IE 7或8中不起作用(但在9、10和11中可以正常工作)。 When running in IE 7 or 8, I get an "unknown exception" in this routine (on the line indicated): 在IE 7或8中运行时,在此例程中(在所指示的行上)出现“未知异常”:

GetPassword().done(function (data) {
    pw = data.d;
    var rdpClient = document.getElementById("rdpClient");
    rdpClient.AdvancedSettings2.ClearTextPassword = pw; **// error occurs here**
});

Any clue why IE 7 and 8 choke on this? 有什么线索为什么IE 7和8会对此造成窒息?

基于此线程 ,我认为这是一个COM +桥问题,无法通过JavaScript访问AdvancedSettings2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM