【发布时间】:2013-03-24 18:30:33
【问题描述】:
在 WindowsPhone 7.8 上使用 WebBrowser 控件时,我遇到了一些 javascript 问题。当我使用href="#" onClick 方法时工作正常,但是当我将其更改为href="javascript:;" 时,onClick 方法不起作用。我尝试在 WindowsPhone 网络浏览器中使用它,没有问题,两个链接都可以正常工作。
这是我的测试页面的完整代码 (http://klamborowski.pl/test/js.html):
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">
<head>
<title>
</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-2" />
<script type="text/javascript">function post_to_url() {
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "http://stackoverflow.com/");
document.body.appendChild(form);form.submit();
}
</script>
</head>
<body>
<b>
<a href="javascript:;" onclick="post_to_url();">Click <br>here - javascript:;</a> <br>
<br>
<br>
<br>
<a href="#" onclick="post_to_url();">Click <br>here - #</a> <br>
</b>
</body>
</html>
以及使用它的 C# 代码:
myWebBrowser.IsScriptEnabled = true;
myWebBrowser.Navigate(new Uri("http://klamborowski.pl/test/js.html"));
提前感谢任何提示和帮助。
编辑:
这只是示例页面。在我的真实项目中,我使用第三方付款页面(包含href="javascript:;"),我无法对其进行任何更改。
【问题讨论】:
-
纯粹出于好奇:为什么要使用
javascript:;而不是#? -
这只是示例页面。在我的真实项目中,我使用第三方支付页面,我无法对其进行任何更改。
标签: javascript windows-phone-7 webbrowser-control windows-phone href