[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

activeX error message 5007 "Object expected" when javascript calling the activeX control is inside a js file

Posted on 2006-05-21
9
Medium Priority
?
1,496 Views
Last Modified: 2008-02-01
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

0
Comment
Question by:cabrera48
  • 5
  • 4
9 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 16730161
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.
0
 

Author Comment

by:cabrera48
ID: 16730163
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"
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 16730183
On what event is your  runX() function called from that generated div?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cabrera48
ID: 16730197
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.  
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 16730277
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";


0
 

Author Comment

by:cabrera48
ID: 16730383
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.
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 2000 total points
ID: 16731791
I wonder why ever your SCRIPT in the innerHTML works.
From my experiance this does NOT work:
<html>
<head>
<title>This example demonstrate that innerHTML script does NOT!!! work</title>
<script>
function appendScript(){
  var newDiv = document.createElement("div");
  newDiv.innerHTML = "Here embbeded the SCR<scr"+"ipt>alert('New Script running!')</scr"+"ipt>IPT.";
  document.body.appendChild(newDiv);
}
</script>
</head>
<body onLoad="appendScript()">
</body>
</html>

The Expert devic produces a great tool called PageSpy: http:M_1344026.html
Whith his tool you can see this page generated:
<HTML><HEAD><TITLE>This example demonstrate that innerHTML script does NOT!!! work</TITLE>
<SCRIPT>
function appendScript(){
  var newDiv = document.createElement("div");
  newDiv.innerHTML = "Here embbeded the SCR<scr"+"ipt>alert('New Script running!')</scr"+"ipt>IPT.";
  document.body.appendChild(newDiv);
}
</SCRIPT>
</HEAD>
<BODY onload=appendScript()>
<DIV>Here embbeded the SCR
<SCRIPT>alert('New Script running!')</SCRIPT>
IPT.</DIV></BODY></HTML>

But the alert() will newer fire.
In your innerHTML you could try to split the word <script> because it is evaluated at html parsing. Then you will see that your running ActiveX is only a misinterpretation side effect.

0
 

Author Comment

by:cabrera48
ID: 16746206
Thanks Zvonko,

That was the answer
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 16746318
You are welcome.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question