Dynamically create object tags in javascript

I am wondering why the following code does not create two from my activex object. When an object tag is directly in HTML, it works fine, but for life, I cannot dynamically create an object. Is this a security issue or something else? I find it difficult to find documentation on this issue.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="InkWebForm._Default" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>         
       <script language="javascript">

           window.onload = function() {
               var s = '<OBJECT id="inkImage" classid="InkControls.dll#InkControls.ResizableInk" VIEWASTEXT></OBJECT>';
               document.getElementById("inkHolder").innerHTML = s;
           };  
       </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>    
    <!-- This one gets created -->
    <OBJECT id="inkImage2" classid="InkControls.dll#InkControls.ResizableInk" VIEWASTEXT>
    </OBJECT>        

    <!-- this one should get inserted but never gets created -->
    <div id="inkHolder"></div>
    </div>
    </form>
</body>
</html>

Well, when I examine dom, the explorer object does show the element, but IE displays a small square field, not an activex control.

Here comes the second attempt, based on a proposal from casablanca. I think there might be a security problem happening here, according to your suggestion, this should work, but it is not. Same problem.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="InkWebForm._Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">       
       <script language="javascript">

           window.onload = function() {

               var obj = document.createElement('object');
               obj.setAttribute('id', 'inkImage');
               obj.setAttribute('classid', 'InkControls.dll#InkControls.ResizableInk');             
               document.getElementById('inkHolder').appendChild(obj);
           };  
       </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
     <OBJECT id="inkImage2" classid="InkControls.dll#InkControls.ResizableInk">
    </OBJECT>   

    <div id="inkHolder"></div>    

    </div>
    </form>
</body>
</html>
+3
1

innerHTML . document.createElement, :

var obj = document.createElement('object');
// set object properties here
document.getElementById('inkHolder').appendChild(obj);

Edit:

, , , ASP, , . JavaScript . HTML , , ASP, JavaScript, .

+1

Source: https://habr.com/ru/post/1752730/


All Articles