Windows Phone 7浏览器无法在html内容中执行javascript [英] Windows phone 7 browser not able to execute the javascript in the html content

查看:62
本文介绍了Windows Phone 7浏览器无法在html内容中执行javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Windows Phone 7测试版的webbrowser控件上显示html5内容。

I am working on displaying the html5 conten on the webbrowser control for windows phone 7 beta release.

I使用以下语法

webBrowser1.IsScriptEnabled =

webBrowser1.IsScriptEnabled =

 

webBrowser1.NavigateToString(@"<!DOCTYPE HTML>< html>< body>< canvas id ="" myCanvas" ;">您的浏览器不支持canvas标记< / canvas>< script type ="" text / javascript""> var canvas = document.getElementById('myCanvas'); var
ctx = canvas.getContext('2d'); ctx.fillStyle ='#FF0000'; ctx.fillRect(0,0,80,100);< / script>< / body>< / html>" );

webBrowser1.NavigateToString(@"<!DOCTYPE HTML><html><body><canvas id=""myCanvas"">your browser does not support the canvas tag </canvas><script type=""text/javascript"">var canvas=document.getElementById('myCanvas');var ctx=canvas.getContext('2d');ctx.fillStyle='#FF0000';ctx.fillRect(0,0,80,100);</script></body></html>");

 

当代码执行
时,它只显示带有边框的白色画布,但没有填充红色clolor或执行任何其他的javascript命令。我还将IsScriptEnabled设置为true。 / span>

当我在浏览器中执行相同的html文件时,它可以正常工作。

When i execute the same html file in a browser it works fine.

如果&bbsp
i我做错了什么,请告诉我。

Please let me know if  i am doing any thing wrong.

问候

susheel tickoo

susheel tickoo

 

 

 

 

推荐答案

我可以确认 - 问题出在

I can confirm that - the problem is in the

<!DOCTYPE html>

<!DOCTYPE html>

标记。虽然带有脚本标记和此doctype的页面在"大浏览器"(独立浏览器)中正​​常工作,但当同一页面加载到"小"WebBrowser时,则根本不执行任何脚本。

mark. While a page with script tags and this doctype works properly in the "big browser" (the standalone one), when the same page is loaded into "small" WebBrowser, then NO SCRIPTS are executed at all.

我尝试过跨域脚本,域内脚本,带有直接代码的脚本标签,以及body-onload等内联脚本。只要doctype到位,就会执行NONE。

I've tried with cross-domain scripts, in-domain scripts, script tags with direct code, and inline scripts like body-onload. NONE were executed as long as the doctype was in place.

当我完全删除

<!DOCTYPE html>

<!DOCTYPE html>

时,或者当我更换它时with 

completely, or when I replaced it with 

<!DOCTYPE html PUBLIC" - // W3C // DTD HTML 4.01 Transitional // EN">

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

然后它立即神奇地开始工作。

then it instantly magically started working.

更有趣的是 - 当html5的doctype到位时,那么只有用HTML编写的脚本被阻止。当您加载页面然后通过WebBrowser.InvokeScript调用某些脚本时 - 它们将被正确执行。我已经加载了整个jQuery
,因为它因为doctype错误而被跳过了..如果它是一个bug。我觉得是这样的。没有其他浏览器表现得那样,甚至连WP7上的大浏览器都没有!!

What's more interesting - when the doctype of html5 is in place, then ONLY the scripts written in the html are blocked. When you load a page and then invoke some scripts via WebBrowser.InvokeScript - then they are executed properly. I've loaded whole jQuery like that, just because it was skipped due to the doctype bug.. if it's a bug. i think it is. no other browser behaves like that, not even the bigbrowser on WP7!!

欢呼,

q


这篇关于Windows Phone 7浏览器无法在html内容中执行javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆