Randy Webb wrote:
> said the following on 9/28/2006 1:45 PM:
>
>> Hi
>>
>> I am very new to javascript and html. My question is how can I move
>> the script from the body section to the head section without affecting
>> how the result of the htm looks?
>> In the example below, I guess the document.write() dumps its results
>> at the location where it is.
>
>
> Yes, that is precisely what it does.
>
>> Thanks for your hints.
>
>
> Hints:
>
> Object/Feature detect before using an object.
Will do.
>
> Functionalize your code and use a function call in the body (overkill to
> me for what you are doing).
Then..... how to move script from the head to the body?
<html>
<head>
<style>
div {border: 1px solid black;}
</style>
<title>XPath - JavaScript Tests</title>
<script>
var xslStylesheet;
var xsltProcessor = new XSLTProcessor();
var myDOM;
var xmlDoc;
function Init() {
// load the xslt file, example1.xsl
var myXMLHTTPRequest = new XMLHttpRequest();
myXMLHTTPRequest.open("GET", "example1.xsl", false);
myXMLHTTPRequest.send(null);
xslStylesheet = myXMLHTTPRequest.responseXML;
xsltProcessor.importStylesheet(xslStylesheet);
// load the xml file, example1.xml
myXMLHTTPRequest = new XMLHttpRequest();
myXMLHTTPRequest.open("GET", "example1.xml", false);
myXMLHTTPRequest.send(null);
xmlDoc = myXMLHTTPRequest.responseXML;
var fragment = xsltProcessor.transformToFragment(xmlDoc, document);
document.getElementById("example").innerHTML = "";
myDOM = fragment;
document.getElementById("example").appendChild(fra gment)
}
</script>
</head>
<body>
<a href="javascript
:Init()">Run XSLT</a>
<div id="example">
</div>
</body>
</html>
Dont want to show contents only after 'click', but immediately, just like the
version written for the IE.
>
>
>>
>>
>> <html>
>> <body>
>>
>> <script type="text/javascript">
>>
>> // Load XML
>> var xml = new ActiveXObject("Microsoft.XMLDOM")
>
>
> And if the browser doesn't support ActiveX or Microsoft.XMLDOM?
>