如何实例化通过 JavaScript 动态加载的 .NET 托管控件?

发布于 2024-08-13 16:00:05 字数 1962 浏览 6 评论 0原文

我正在尝试使用 JavaScript 动态地将一堆 .NET 托管控件加载到页面中进行注入将 OBJECT 标记添加到 HTML 中。

我的问题是对象不会实例化,只会出现页面加载时可见的静态对象。有什么方法可以加载这些对象吗?


<h1>
    Visible static</h1>
  <div id="staticObject">
    <object id="Object1" name="dropfolder" classid="http:DropFolder.dll#DropFolder.DropFolder">
      <param name="FolderName" value="Intranet only - Worcs">
      <param name="NodeKey" value="default|Intranet">
      <param name="DropAction" value="">
    </object>
  </div>
  <h2>
    Hidden static</h2>
  <div id="objwrap" style="display: none;">
    <object id="default_Intranet" name="dropfolder" classid="http:DropFolder.dll#DropFolder.DropFolder">
      <param name="FolderName" value="Intranet only - Worcs">
      <param name="NodeKey" value="default|Intranet">
      <param name="DropAction" value="">
    </object>
  </div>
  <input type="button" value="unhide!" onclick="document.getElementById('objwrap').style.display = 'block';" />
  <h2>
    OnLoad target</h2>
  <div id="objectTarget1">
  </div>
  <h2>
    Click target</h2>
  <div id="objectTarget2">
  </div>
  <input type="button" value="inject" onclick="javascript:inject('objectTarget2');" />

  <script type="text/javascript">
    function inject(target) {
      var target = document.getElementById(target);
      target.innerHTML =
      '<object id="default_Intranet" name="dropfolder" classid="http:DropFolder.dll#DropFolder.DropFolder">' +
        '<param name="FolderName" value="Intranet only - Worcs">' +
        '<param name="NodeKey" value="default|Intranet">' +
        '<param name="DropAction" value="">' +
      '</object>';
    };

    inject('objectTarget1');
  </script>

I am trying to load a bunch of .NET hosted controls into a page dynamically using JavaScript to inject OBJECT tags into the HTML.

My problem is that the objects do not instantiate, only the static object that is visible on page load will appear. Is there any way to get these objects to load?


<h1>
    Visible static</h1>
  <div id="staticObject">
    <object id="Object1" name="dropfolder" classid="http:DropFolder.dll#DropFolder.DropFolder">
      <param name="FolderName" value="Intranet only - Worcs">
      <param name="NodeKey" value="default|Intranet">
      <param name="DropAction" value="">
    </object>
  </div>
  <h2>
    Hidden static</h2>
  <div id="objwrap" style="display: none;">
    <object id="default_Intranet" name="dropfolder" classid="http:DropFolder.dll#DropFolder.DropFolder">
      <param name="FolderName" value="Intranet only - Worcs">
      <param name="NodeKey" value="default|Intranet">
      <param name="DropAction" value="">
    </object>
  </div>
  <input type="button" value="unhide!" onclick="document.getElementById('objwrap').style.display = 'block';" />
  <h2>
    OnLoad target</h2>
  <div id="objectTarget1">
  </div>
  <h2>
    Click target</h2>
  <div id="objectTarget2">
  </div>
  <input type="button" value="inject" onclick="javascript:inject('objectTarget2');" />

  <script type="text/javascript">
    function inject(target) {
      var target = document.getElementById(target);
      target.innerHTML =
      '<object id="default_Intranet" name="dropfolder" classid="http:DropFolder.dll#DropFolder.DropFolder">' +
        '<param name="FolderName" value="Intranet only - Worcs">' +
        '<param name="NodeKey" value="default|Intranet">' +
        '<param name="DropAction" value="">' +
      '</object>';
    };

    inject('objectTarget1');
  </script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

許願樹丅啲祈禱 2024-08-20 16:00:05

你可以尝试:

function inject(target) {
  var obj = document.createElement("object");

  obj.id = "default_Intranet";
  obj.name = "dropFolder";
  obj.classid = "http:DropFolder.dll#DropFolder.DropFolder";

  var param1 = document.createElement("param");
  param1.name = "FolderName";
  param1.value = "Intranet only - Worcs";
  obj.appendChild(param1);
  // repeat for other params

  document.getElementById(target).appendChild(obj);
}

You could try:

function inject(target) {
  var obj = document.createElement("object");

  obj.id = "default_Intranet";
  obj.name = "dropFolder";
  obj.classid = "http:DropFolder.dll#DropFolder.DropFolder";

  var param1 = document.createElement("param");
  param1.name = "FolderName";
  param1.value = "Intranet only - Worcs";
  obj.appendChild(param1);
  // repeat for other params

  document.getElementById(target).appendChild(obj);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文