cabrera48
asked on
activeX error message 5007 "Object expected" when javascript calling the activeX control is inside a js file
I have the following script inside a js file:
function runX(arg1,title,ID)
{ try
{
var myXobj = new ActiveXObject("PodObject.P odService" );
AddXtoPC(arg1,title,ID); // Open popup to add channel to PC
}
catch(e)
{
// Service is not present, ask for installation
showInstallX(arg1,title,ID ); // Open popup to ask for download of PodObject
}
}
It works perfect when I call it directly from my HTML page. But when I call it from a <div> layer that is dynamically generated and appended to the same page with an onClick event, I get a really strange behavior.
The first time I click on the button to call the js file, I get the following error message (coming from the activeX control): "Object expected", the error message is 5007. This happens even if the PodObject.PodService is present. So the wrong function gets called:showInstallX() .
The weird thing is that the second time I click on the button, it works !?!?!?! ... I do not get an error message, and the right function gets called ( AddXtoPC() ).
I would understand if this does not work on the first click, or the second, or any other click afterwards, I would assume something is wrong with my activeX control and can't be found for some reason by the javascript call, but the fact that does not work on the first, and later it does on the second click is driving me insane.
Does anybody have a clue what can be happening?
Does anybody know what error message 5007 mean? I try searching the internet for a comprehensive error message guide to activeX error messages, but could no t find anything.
Thanks
function runX(arg1,title,ID)
{ try
{
var myXobj = new ActiveXObject("PodObject.P
AddXtoPC(arg1,title,ID); // Open popup to add channel to PC
}
catch(e)
{
// Service is not present, ask for installation
showInstallX(arg1,title,ID
}
}
It works perfect when I call it directly from my HTML page. But when I call it from a <div> layer that is dynamically generated and appended to the same page with an onClick event, I get a really strange behavior.
The first time I click on the button to call the js file, I get the following error message (coming from the activeX control): "Object expected", the error message is 5007. This happens even if the PodObject.PodService is present. So the wrong function gets called:showInstallX() .
The weird thing is that the second time I click on the button, it works !?!?!?! ... I do not get an error message, and the right function gets called ( AddXtoPC() ).
I would understand if this does not work on the first click, or the second, or any other click afterwards, I would assume something is wrong with my activeX control and can't be found for some reason by the javascript call, but the fact that does not work on the first, and later it does on the second click is driving me insane.
Does anybody have a clue what can be happening?
Does anybody know what error message 5007 mean? I try searching the internet for a comprehensive error message guide to activeX error messages, but could no t find anything.
Thanks
ASKER
If it would help, these are my javascript debugging statements, and the messages they generate:
alert(e.description); // Generates: "Object expected"
alert(e.messsage); // Generates: ""undefined"
alert(e.number & 0xFFFF); // Generates: "5007"
alert(e.name); // Generates: "TypeError"
alert(e.description); // Generates: "Object expected"
alert(e.messsage); // Generates: ""undefined"
alert(e.number & 0xFFFF); // Generates: "5007"
alert(e.name); // Generates: "TypeError"
On what event is your runX() function called from that generated div?
ASKER
This is the code that dynamically generates the <div> file:
<script language="javascript">
function generate_popup() {
runX(arg1,title,ID)
}
</script>
<a href='#' onclick="var myScript = document.createElement('sc ript');
arg1='Test';
title='Add+New+Show+Test+1 234';
ID='9C75466A-ABCA-412F-A16 5-EEBCA7E2 3B11';
podbridgeScript.src = 'http://www.myscriptlocation.com/test/openpopups.js';
document.body.appendChild( myScript); return false;">
openpopups.js is the js file containing the activeX check function runX(), and generate_popup() is called from inside that js as well.
<script language="javascript">
function generate_popup() {
runX(arg1,title,ID)
}
</script>
<a href='#' onclick="var myScript = document.createElement('sc
arg1='Test';
title='Add+New+Show+Test+1
ID='9C75466A-ABCA-412F-A16
podbridgeScript.src = 'http://www.myscriptlocation.com/test/openpopups.js';
document.body.appendChild(
openpopups.js is the js file containing the activeX check function runX(), and generate_popup() is called from inside that js as well.
On what event is generate_popup() function called? Simply as a function cal inside of openpopups.js?
Can we see the sequence?
Also I do not see where the object podbridgeScript is created or what it has to do with myScript object.
Can you set the defer attribute like this:
myScript.defer = "defer";
Can we see the sequence?
Also I do not see where the object podbridgeScript is created or what it has to do with myScript object.
Can you set the defer attribute like this:
myScript.defer = "defer";
ASKER
Sorry Zvonko I did not give you enough details, the entire implementation is huge, I just did not want you to be reading all of the js files and functions involved, I just wanted to give the code relative to the problem. But working my way commenting code out, I find out the following code is the one creating the problem:
// Build the virtual popup HTML line by line just so we have a good visual about what we are building:
virtualPopupHTML += "<script>";
virtualPopupHTML += "try {";
virtualPopupHTML += " var xObj = new ActiveXObject('PodObject.P odService' );";
virtualPopupHTML += "reply = xObj.AddFeed(" + arg1 + "," + title + ");";
virtualPopupHTML += "} catch(e) { alert(e); // No catch, should never happen }";
virtualPopupHTML += "</script>";
virtualPopupHTML += "<p> Test add channel </p>" + title + " and url: " + arg1;
virtualPopup.innerHTML = virtualPopupHTML;
// Reset the variable so we can reuse it later for other buttons:
virtualPopupHTML = '';
//virtualPopup.appendChild (sample_te xt);
document.body.appendChild( virtualPop up);
virtualPopup is the <div> dynamically generated. It looks like using innerHTML makes the activeX object not be found on the first try.
// Build the virtual popup HTML line by line just so we have a good visual about what we are building:
virtualPopupHTML += "<script>";
virtualPopupHTML += "try {";
virtualPopupHTML += " var xObj = new ActiveXObject('PodObject.P
virtualPopupHTML += "reply = xObj.AddFeed(" + arg1 + "," + title + ");";
virtualPopupHTML += "} catch(e) { alert(e); // No catch, should never happen }";
virtualPopupHTML += "</script>";
virtualPopupHTML += "<p> Test add channel </p>" + title + " and url: " + arg1;
virtualPopup.innerHTML = virtualPopupHTML;
// Reset the variable so we can reuse it later for other buttons:
virtualPopupHTML = '';
//virtualPopup.appendChild
document.body.appendChild(
virtualPopup is the <div> dynamically generated. It looks like using innerHTML makes the activeX object not be found on the first try.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Zvonko,
That was the answer
That was the answer
You are welcome.
Show your not working dynamic html creation script.