Link to home
Start Free TrialLog in
Avatar of cabrera48
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.PodService");
            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

Avatar of Zvonko
Zvonko
Flag of North Macedonia image

It is not clear to me what sequence of events you mean when say you generate a div on a click.
Show your not working dynamic html creation script.
Avatar of cabrera48
cabrera48

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"
On what event is your  runX() function called from that generated div?
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('script');
                  arg1='Test';
                  title='Add+New+Show+Test+1234';
                  ID='9C75466A-ABCA-412F-A165-EEBCA7E23B11';
                  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.  
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";


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.PodService');";
            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_text);
            document.body.appendChild(virtualPopup);

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
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Zvonko,

That was the answer
You are welcome.