Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IE Behaviours (.htc vs .sct)

Status
Not open for further replies.
Dec 8, 2003
17,047
GB
Hi all...

I'm trying to fathom out the difference between using X-Scriptlet (.sct) files and HTML Component (.htc) files with IE behaviours.

I can include identical code in both formats, with only the interface changing, and they both function in exactly the same way.

I had previously been told that X-Scriptlets allowed you to override default HTML properties (things like 'disabled', etc), whereas HTML Components did not - but this appears not to be the case.

I know that you can also include X-Scriptlets on the page using OBJECT tags, but at the moment, I'm just interested in the differences between the formats when used as behaviours.

Can anyone tell me the difference between the two formats? Are there any limitations with one over the other? Is one faster, better, less CPU intensive, etc etc etc? I'm struggling to find any differences myself.

Here's a quick test-harness to show the identical code in both formats:

dummyBehaviour.htc
Code:
<public:component>
	<public:property name=&quot;prop&quot; get=&quot;get_prop&quot; put=&quot;put_prop&quot; />
	<public:method name=&quot;showProp&quot; />

	<script type=&quot;text/javascript&quot;>
		var _prop = '';
		function get_prop()           { return (_prop);             }
		function put_prop(paramValue) { _prop = paramValue;         }
		function showProp()           { alert(_prop.toUpperCase()); }
	</script>
</public:component>

dummyBehaviour.sct
Code:
<scriptlet>
	<implements type=&quot;behavior&quot; default />
	<implements type=&quot;automation&quot;>
		<public:property name=&quot;prop&quot; get=&quot;get_prop&quot; put=&quot;put_prop&quot; />
		<public:method name=&quot;showProp&quot; />
	</implements>

	<script type=&quot;text/javascript&quot;>
		var _prop = '';
		function get_prop()           { return (_prop);             }
		function put_prop(paramValue) { _prop = paramValue;         }
		function showProp()           { alert(_prop.toUpperCase()); }
	</script>
</scriptlet>

testHarness.html
Code:
<html>
<head>
<style type=&quot;text/css&quot;>
span.htc { behavior: url(dummyBehaviour.htc); }
span.sct { behavior: url(dummyBehaviour.sct); }
</style>
</head>

<body>
	<span class=&quot;htc&quot; id=&quot;dummyHTCspan&quot; prop=&quot;dummy htc property value&quot;>htc span</span>
	<br>
	<span class=&quot;sct&quot; id=&quot;dummySCTspan&quot; prop=&quot;dummy sct property value&quot;>sct span</span>
	<br><br>

	Click <a href=&quot;javascript:alert(document.getElementById('dummyHTCspan').prop);&quot;>here</a> to display property 'prop' (htc)
	<br>
	Click <a href=&quot;javascript:document.getElementById('dummyHTCspan').showProp();&quot;>here</a> to execuite 'showProp()' method (htc)
	<br><br>
	Click <a href=&quot;javascript:alert(document.getElementById('dummySCTspan').prop);&quot;>here</a> to display property 'prop' (sct)
	<br>
	Click <a href=&quot;javascript:document.getElementById('dummySCTspan').showProp();&quot;>here</a> to execuite 'showProp()' method (sct)
</body>
</html>

The code above doesn't do anything too fancy - it's just a demo to illustrate including behaviours on the page. It lets you set and get the value of the &quot;prop&quot; property. If you get it by name (
Code:
.prop
), it returns as-is, and if you execute the
Code:
showProp()
method, it alerts it in uppercase.

Documentation on MSDN seems to be sketchy, and a lot of it is now out of date. Much of what is lying around on the 'net seems not to use the interface format that I have above, so I can't really compare differences.

Any help in finding differences between the two formats will be greatly appreciated.

Thanks in advance!

Dan
 
Hmm..

I managed to find only one difference so far - you cannot use HTML comment tags in .sct files to hide the scripting... So using:

Code:
<script type=&quot;text/javascript&quot;>
<!--
     ....
//-->
</script>

Would fail to run any of the script. The .htc file seemed to have no such limitation.

But still, I cannot seem to find any real differences between the formats ;o(

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top