PDA

View Full Version : Object doesn't support this property or method - ActiveX



nikhilbansal
07-12-2011, 03:11 PM
Hi All,

Need some urgent.

We are having a javascript which is throwing the foll error

"Object doesn't support this property or method".

The javascript function being called is using a Scanner API. So this is using some ActiveX.


Below is the code for javascript

<script language="javascript">

// Initialize scanning
function OnLoad()
{
try
{
Scanner.OpenScanner();
// Scanner.ScanPriority = 0; // Set scanner to Foreground Read mode before enable scanning
// Scanner.EnableScanning(1);
document.forms["mobileform"]["rm07m-bwartwe[1]"].value = "101";
}
catch (e)
{
alert(e.message);
}
}

// Clean up
function OnUnload()
{
Scanner.CloseScanner();
// Calling Dispose is necessary for Pocket IE because of a Microsoft issue related to releasing object.
if (navigator.appName == "Microsoft Pocket Internet Explorer")
Scanner.Dispose();
}

// Scan through soft trigger
function Scan()
{
try
{
Scanner.SetSoftTrigger(1);
}
catch (e)
{
alert(e.message);
}
}

//User-defined function to format error codes.
//VBScript has a Hex() function but JScript does not.
function hex(nmb)
{
if (nmb > 0)
return nmb.toString(16);
else
return (nmb + 0x100000000).toString(16);
}

</script>

There is a object tag in html

<object id="Scanner"></object>

The javascript functions are called from body tag.

Can someone please provide some help.

Thanks,
Nikhil

Old Pedant
07-12-2011, 10:17 PM
I assume you know that ActiveX will only work in MSIE browsers?

But in any case, that <object> tag is incomplete. Did you only show a small part of it?

And, finally, you don't bother to say WHICH LINE you are getting the error from.

nikhilbansal
07-14-2011, 04:26 PM
Hi,

The complete object tag is as follows

<OBJECT id=Scanner style="LEFT: 0px; WIDTH: 0px; TOP: 0px; HEIGHT: 0px"
classid=clsid:5FFAA94A-D9E2-405d-9644-EE2196713A3C>
</OBJECT>

I am getting the error in the following line

Scanner.OpenScanner();


Thanks,
Nikhil

Old Pedant
07-14-2011, 11:49 PM
Hmmm...can't tell.

You really should have "..." around the classid. But it *probably* isn't needed.

I assume that you have ensured that the Scanner object is indeed installed and registered on the computer where you are attempting this? Have you checked the registry?

alykins
07-15-2011, 01:08 AM
i think the issue is in how you ID'd it... try encasing the id in ""s so id="Scanner"... i am not too sure if this will fix it, but the way i am reading this error is not in relation to the tag <object>... i think that is just a coincidence... my insight comes from doing thins in C#... and yes i know this is javascript, but langs are similar.. a method or property is applied to an object... everything in your code is an object, the tags are objects, even the classes can be objects... i think what is happening is the "object" which is Scanner is not able to be found because it is not contained in "" 's... i could be wrong, but it is a simple "quick fix" that you could try

Old Pedant
07-15-2011, 02:06 AM
If this weren't MSIE, I'd agree with you alykins.

But MSIE *does* treat objects (of any kind...including <div> and <tr> and so on, not just <object>) as global variables when you refer to them by their ID.

In other words, where other browsers would want you to do

var Scanner = document.getElementById("Scanner");

MSIE makes that assignment, implicitly. (At least it did so up until MSIE 8....your mileage my vary in MSIE 9, which tries to be more standards compliant.)

My *gut* feeling is that the ActiveX control is not installed on the machine that is trying to use this script. But that's just a feeling.

alykins
07-15-2011, 03:17 AM
question... don't you need to pull the document id of Scanner before you can reference it? or at least tell the script to look in the document to find it?