<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" style="height: 99%;"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Project - CANopenNode</title>
<style type="text/css">
body{
background-color: rgb(165, 186, 221);
margin: 0px;
height: 100%;
}
table{
width: 100%;
}
td {
border: 1px solid black;
padding: 1px 0.6em 1px 0.3em;
width: 50%;
}
table div{
position: relative;
height: 2em;
margin-top: 0.3em;
}
table pre{
margin: 0px;
}
textarea{
width: 100%;
height: 10em;
}
.right{
position: absolute;
right: 0px;
}
</style>
<script type="javascript">
var editorWindowOK = false;
function getURLPath(path)
{
//Function returns absolute path based on input path. If input path is relative, it is relative to path of this html
//Input path can be one of the following (either '/' or '\' can be used):
//- http://www.example.com/example/example.html
//- file:///C:/example/example.html
//- C:/example/example.html
//- example/example.html
//- /example/example.html
//- ../example/example.html
var absloutePath;
path = path.replace(/\\/g,"/");
var i = path.indexOf(":");
if(i >= 0)
{
absloutePath = path;
if(i == 1) absloutePath = "file:///" + absloutePath;
}
else
{
absloutePath = location.href;
absloutePath = absloutePath.substring(0, absloutePath.lastIndexOf("/"));
while(path.substring(0, 3) == "../"){
path = path.substring(3);
absloutePath = absloutePath.substring(0, absloutePath.lastIndexOf("/"));
}
var hash = "/";
if(path.charAt(0) == "/") hash = "";
absloutePath = absloutePath + hash + path;
}
return absloutePath;
}
function getLocalPath(path)
{
//Function returns absolute path based on input path. If input path is relative, it is relative to path of this html
//Input path can be one of the following (either '/' or '\' can be used):
//- C:\example\example.html
//- example\example.html
//- \example\example.html
//- ..\example\example.html
path = path.replace(/\//g,"\\");
if(path.indexOf(":") >= 0) return path;
var absloutePath = location.href;
if(absloutePath.substring(0, 8) != "file:///") return "";
absloutePath = absloutePath.substring(8, absloutePath.lastIndexOf("/"));
absloutePath = absloutePath.replace(/\//g,"\\");
while(path.substring(0, 3) == "..\\")
{
path = path.substring(3);
absloutePath = absloutePath.substring(0, absloutePath.lastIndexOf("\\"));
}
var hash = "\\";
if(path.charAt(0) == "\\") hash = "";
absloutePath = absloutePath + hash + path;
return absloutePath;
}
function updateFileName(field, name){
document.getElementById(field).setAttribute("fileName", name);
}
function loadProject(name)
{
var loc = getURLPath(name);
var req = new XMLHttpRequest();
req.open('GET', loc, false);
req.send(null);
document.getElementById('textXML').value = req.responseText;
}
function updateFields()
{
var xmlText = document.getElementById("textXML");
var el = xmlText.value.substring(xmlText.value.indexOf("<file"));
var el = el.substring(0, el.indexOf("/>")+2);
var filename = ""
if(el.length){
var el = new XML(el);
fileName = el.@fileName.toString();
document.title = fileName + " - CANopenNode";
var span = document.getElementById("title");
span.replaceChild(document.createTextNode(fileName), span.firstChild);
var date = "V " + el.@fileVersion.toString() + "; Updated: " + el.@fileCreationDate.toString() + ", " +
el.@fileCreationTime.toString() + ", by " +
el.@fileCreator.toString();
span = document.getElementById("date");
span.replaceChild(document.createTextNode(date), span.firstChild);
}
//for use with firefox addon "Save Text Area 0.4.5"
//https://addons.mozilla.org/en-US/firefox/addon/1046
updateFileName("textXML", "_project.xml");
updateFileName("textHTM", fileName+".html");
updateFileName("textODH", "CO_OD.h");
updateFileName("textODC", "CO_OD.c");
updateFileName("textEDS", fileName+".eds");
updateFileName("textXDD", fileName+".xdd");
document.getElementById("iframe").src = "";
}
function openEditor(newWindow)
{
var path = document.getElementById("locEditor").value;
var loc = getURLPath(path + "/device.xul");
if(newWindow){
editorWindow = window.open(loc, '_blank',
'left=0,top=150,width=1024,height=768,resizable=yes,scrollbars=yes,location=no,status=no');
editorWindow.focus();
}
else
{
var iframe = document.getElementById("iframe");
iframe.src = loc;
editorWindow = iframe.contentWindow;
}
document.getElementById("textHTM").value = "-";
document.getElementById("textODH").value = "-";
document.getElementById("textODC").value = "-";
document.getElementById("textEDS").value = "-";
document.getElementById("textXDD").value = "-";
//verify if editor window is OK
editorWindowOK = false;
setTimeout(verifyEditorWindow, 10000);
}
function verifyEditorWindow()
{
if(editorWindowOK == false)
alert("Error with Editor!\n(Wrong location)");
}
function openAbout()
{
var path = document.getElementById("locEditor").value;
var loc = getURLPath(path + "/about.html");
var w = window.open(loc, 'About',
'left=0,top=150,height=600,width=800,resizable=yes,scrollbars=yes,location=yes,status=yes');
w.focus();
}
function receiveMessage(event)
{
//function receives a message from editor window, which is editing a project file. This event is triggered
//after editor sends some data. For more information see http://developer.mozilla.org/en/DOM/window.postMessage
//if (event.origin !== "http://example.com:8080") return; //for safety
var head = event.data.substring(0, 3); //first three characters of the message
var body = event.data.substring(3); //other text of the message
switch(head){
case "RDY": //editor was loaded
editorWindow.postMessage(document.getElementById('textXML').value, '*');
document.getElementById("fileBoxes").style.display = "none";
document.getElementById("iframe").style.height = "100%";
editorWindowOK = true;
break;
case "CLS": //editor was closed
document.getElementById("iframe").style.height = "0px";
document.getElementById("fileBoxes").style.display = "block";
break;
case "XML": //xml contents was sent
var tb = document.getElementById("textXML");
tb.value = body;
//tb.setAttribute("value", body); //faster code
updateFields();
break;
case "HTM": //html contents was sent
var tb = document.getElementById("textHTM");
tb.value = body;
//tb.setAttribute("value", body); //faster code
break;
case "ODH": //CO_OD.h contents was sent
var tb = document.getElementById("textODH");
tb.value = body;
//tb.setAttribute("value", body); //faster code
break;
case "ODC": //CO_OD.c contents was sent
var tb = document.getElementById("textODC");
tb.value = body;
//tb.setAttribute("value", body); //faster code
break;
case "EDS": //EDS contents was sent
var tb = document.getElementById("textEDS");
tb.value = body;
//tb.setAttribute("value", body); //faster code
break;
case "XDD": //XDD contents was sent
var tb = document.getElementById("textXDD");
tb.value = body;
//tb.setAttribute("value", body); //faster code
break;
default: alert("Message command was not recognized: " + head);
}
}
window.addEventListener("message", receiveMessage, false);
function viewFile(value, pre)
{
var w = window.open("", '_blank',
'left=0,top=150,width=1024,height=768,resizable=yes,scrollbars=yes,location=yes,status=yes,menubar=yes');
w.document.open();
if(pre)
{
value = value.replace(/&/g, "&");
value = value.replace(/</g, "<");
value = value.replace(/>/g, ">");
w.document.write("<pre>"+value+"</pre>");
}
else
{
w.document.write(value);
//disable anchors
var anchors = w.document.getElementsByTagName("a");
for(var i = 0; i < anchors.length; i++){
anchors[i].removeAttribute("href");
}
}
w.document.close();
}
</script>
</head>
以上是我html的全部代码,其中所有调用javasrcipt的地方,都会提示 未定义的错误,怎么回事呢。?