Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3692682
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:17:25+00:00 2026-05-19T04:17:25+00:00

I have a problem with dynamically including an object-tag in my html. We have

  • 0

I have a problem with dynamically including an object-tag in my html.
We have a external service which we call to get some html-fragment, it includes an object-tag, a script and a simple html-form. I take that content and add it to a div in my page and then try to execute the script that uses the included object. When i debug using Firebug I can see that the code is correctly inserted in the page but the script gets an error when it tries to access the object. It seems to me that the object isn’t initialized. Let me show you some code to exemplify what I mean.

getFragment makes an ajax call using jQuery to get the content.

var htmlSnippet = RequestModule.getFragment( dto );
$('#plugin').html( htmlSnippet ).hide();

The included content in plugin-div looks like this

<div id="plugin" style="display: none; ">
    Browser:
    Chrome
    <object name="signer" id="signer" type="application/x-personal-signer2"></object>

<form method="POST" name="signerData" action="#success">
    <input name="nonce" value="ASyhs..." type="hidden">
    <input name="signature" value="" type="hidden">
    <input name="encodedTbs" value="U2l..." type="hidden">
    <input name="provider" value="nexus-personal_4X" type="hidden">

    <input type="submit" onclick="doSign()" value="Sign">
</form>
</div>

The javascript that tries to use the “signer” object looks like this:

function doSign(){
    var signer2 = document.getElementById("signer");

   retVal = signer2.SetParam('TextToBeSigned', 'some value...');

   ... and then some more
}

It’s when i call the signer2.SetParam method that I get an error saying

Object #<an HTMLObjectElement> has no method 'SetParam'

But when I use the original page where the content is loaded when the page loads the script works so I know that the ‘SetParam’ method exists on the object and that the script works. But somehow it doesn’t work when I dynamically add it to the page afterwards.

I’ve Googled this a lot the last couple of days with no luck.
Does anyone have any idea on how to get this to work?

Best regards,
Henrik

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:17:25+00:00Added an answer on May 19, 2026 at 4:17 am

    First of all Object tag is not fully supported in all browsers (Source)
    Next, from my experience, jQuery (which heavily relies on document.createDocumentFragment) sometimes fails to attach/trigger events on dynamically created/cloned DOM nodes, which could explain why your object failed to initialize.

    That said, to try and fix your problem, I suggest using native document.createElement and document.appendChild methods instead of jQuery.html. You can try document.innerHTML but if that fails, you can always go with the ones I mentioned earlier.

    My suggestion is to either alter your service to replace:

    <script type="text/javascript">
    function addElement(parentid, tag, attributes) {
        var el = document.createElement(tag);
        // Add attributes
        if (typeof attributes != 'undefined') {
            for (var a in attributes) {
              el.setAttribute(a, attributes[a]);
            }
        }
    
        // Append element to parent
        document.getElementById(parentid).appendChild(el);
    }
    addElement('plugin', 'object', {name:"signer",id:"signer",type:"application/x-personal-signer2"});
    </script>
    

    OR if you cannot change the content that is returned by the service, run this after you include the content onto your page:

    <script type="text/javascript">
        /*
         * Goes through al the object tags in the element with the containerid id
         * and tries to re-create them using the DOM builtin methods
         */
        function reattachObjectTags(containerid) {
            jQuery('#'+containerid+' object').each(function(){
                var attrs = {}, el = this;
                // We're insterested in preserving all the attributes
                var saved_attrs = {}, attr;
                for(var i=0; i < el.attributes.length; i++) {
                    attr = el.attributes.item(i);
                    if(attr.specified) {
                        saved_attrs[attr.nodeName]=attr.nodeValue;
                    }
                }
                this.parentNode.removeChild(this);
    
                var new_element = document.createElement('object');
                for (var a in saved_attrs) {
                    new_element.setAttribute(a,saved_attrs[a]);
                }
                document.getElementById(containerid).appendChild(new_element);
            });
        }
    
        // Do your stuff
        var htmlSnippet = RequestModule.getFragment( dto ); 
        $('#plugin').html( htmlSnippet ).hide();
        // reattach all the object elements in #plugin
        reattachObjectTags('plugin');
    </script>
    
    • THIS IS ALL UNTESTED –
      I typed this off the top of my mind, since I don’t have the means to fire up IE and test this.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem in some JavaScript that I am writing where the Switch statement
I have problem when I try insert some data to Informix TEXT column via
I have a problem with a little .Net web application which uses the Amazon
I have a problem in my project with the .designer which as everyone know
I have problem with handling dynamically created Buttons on Android. I'm creating N buttons
Im having a problem dynamically loading beans in my program. I have my facelet
I have a problem working with ScriptManager's RegisterClientScriptBlock which is not working. I have
I have a problem getting some script to run in a wordpress widget when
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.