Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WebBrowser.InvokeScript()引发错误:80020006_C#_Javascript_Windows Phone 8_Webbrowser Control - Fatal编程技术网

C# WebBrowser.InvokeScript()引发错误:80020006

C# WebBrowser.InvokeScript()引发错误:80020006,c#,javascript,windows-phone-8,webbrowser-control,C#,Javascript,Windows Phone 8,Webbrowser Control,我正在开发一个Windows Phone 8应用程序,我是Windows Phone 8的新手 我正在使用WebBrowser控件并尝试加载包含javascript的html页面 在button_Click事件中,我调用Webbrowser.InvokeScript(“JavascriptFunctionName”),但它总是抛出错误:80020006,即使Webbrowser.isScriptEnabled=true 下面是代码 Html页面:MyHtmlPage.Html <!DOCT

我正在开发一个Windows Phone 8应用程序,我是Windows Phone 8的新手

我正在使用WebBrowser控件并尝试加载包含javascript的html页面

在button_Click事件中,我调用Webbrowser.InvokeScript(“JavascriptFunctionName”),但它总是抛出错误:80020006,即使Webbrowser.isScriptEnabled=true

下面是代码

Html页面:MyHtmlPage.Html

<!DOCTYPE html>
<html>
<head title="test">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
    html {
        height: 100%;
    }

    body {
        height: 100%;
        margin: 0;
        padding: 0;
    }

    #map-canvas {
        height: 100%;
    }
</style>

<script type="text/javascript">
    function initialize() {

        var helloText = document.getElementById("Hello");
        helloText.textContent = "Initialized";

        return ("Initialize");

    }

</script>
</head>
<body>
    <div id="test-canvas" />
    <label id="Hello">Hello</label>
</body>
</html>
}

帮帮我。。
谢谢。

在WP8下使用
NavigateToString
时,脚本不会执行。下面的测试证明了这一点,车身背景色不会变成红色

<script type="text/javascript">
    document.body.style.backgroundColor = "red";

    window.initialize = function() {
        document.body.style.backgroundColor = "blue";

        var helloText = document.getElementById("Hello");
        helloText.textContent = "Initialized";

        return ("Initialize");
    }
</script>

document.body.style.backgroundColor=“红色”;
window.initialize=函数(){
document.body.style.backgroundColor=“蓝色”;
var helloText=document.getElementById(“Hello”);
helloText.textContent=“已初始化”;
返回(“初始化”);
}
一种可能的解决方案是在隔离存储中创建一个临时文件,如下所示


另一个选项是使用
导航(“about:blank”)
导航到空白页面,处理事件,然后注入所需的HTML和脚本,如前所述。

@UweKeim,不是这样的。我们确定在OP的情况下,
s
根本不运行,尽管不清楚原因。感谢他的回复,但它不起作用。。相同的错误背景色没有变化。我还尝试使用WebBrowser.Navigate(),但它也不起作用。这意味着,
标记没有得到执行。首先解决此问题,然后返回
WebBrowser.InvokeScript
。我建议你把它作为一个单独的问题发布。使用正确的标签-注意我是如何编辑您的问题标签的。
<script type="text/javascript">
    document.body.style.backgroundColor = "red";

    window.initialize = function() {
        document.body.style.backgroundColor = "blue";

        var helloText = document.getElementById("Hello");
        helloText.textContent = "Initialized";

        return ("Initialize");
    }
</script>