I have a problem with dynamically including an object tag in my html. We have an external service that we call to get some html fragment, it includes a tag object, a script and a simple html form. I take this content and add it to a div on my page, and then try to execute a script that uses the included object. When I debug using Firebug, I see that the code is correctly inserted into the page, but the script receives an error message when trying to access the object. It seems to me that the object is not initialized. Let me show you some code to show 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 the plugin-div is as follows
<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 is trying to use the "signer" object is as follows:
function doSign(){
var signer2 = document.getElementById("signer");
retVal = signer2.SetParam('TextToBeSigned', 'some value...');
... and then some more
}
Its when I call the signer2.SetParam method, I get an error
Object
But when I use the source page on which the content is loaded, when the page loads the script work, I know that there is a SetParam method for the object and that the script works. But for some reason this does not work when I dynamically add it to the page later.
Ive googled this a lot the last couple of days with no luck. Does anyone know how to make this work?
Regards, Henrik
source
share