从htm页面调用函数

时间:2012-05-25 23:39:08

标签: javascript silverlight

我有一些带有jscript函数的html页面Page.htm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title></title>
</head>
<script  language="javascript">

function WriteFile(val) {
    var file = new ActiveXObject("Scripting.FileSystemObject");
    var fc = file.CreateTextFile("Res", true);
    fc.WriteLine(val);//it will be string.without variants
    fc.Close();
}

function ReadFile() {
    var file = new ActiveXObject("Scripting.FileSystemObject");
    var fc = file.OpenTextFile("Res", true);
    var s = fc.readall;
    fc.Close();
    return s;
}

function Request(city) {
    var xmlhttp;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(E) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    var s = 'http://www.google.com/ig/api?weather=' + city + '&hl=en&oe=utf-8';
    xmlhttp.open('GET', s, false);
    xmlhttp.send(null);
    if (xmlhttp.status == 200) {
        return xmlhttp.responseText;
    }
    return "error!";
}
</script>
   <body>
   </body> 
</html>

但是当我尝试调用函数WriteFile时,我得到了InvalidOperationException

HtmlPage.Window.Invoke("WriteFile", new string[] {"hello world!"});

文件Page.html不可见或什么?

0 个答案:

没有答案