window.external有什么用?这是否用于从 JavaScript 调用 C#/VB.NET (ASP.NET) 中的服务器端函数/方法?你能给我指出正确的方向吗?
代码:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" name="button1" value="Click"
onclick="javascript:window.external.SayHello('Mike');" />
</div>
</form>
</body>
</html>
Public Class WebForm1
Inherits System.Web.UI.Page
Public Sub SayHello(ByVal name As String)
Response.Write("Hello :- " & name)
End Sub
End Class
最佳答案
这主要取自 MSDN article但是 window.external
可用于允许您的 WebBrowserControl
执行客户端 Windows 窗体应用程序的公共(public)方法。
例如,在您的表单中,您可能具有如下功能:
public void HelloFromTheForm()
{
MessageBox.Show("Hi client, thanks for calling me!");
}
在加载到您的 WebBrowserControl
中的 html 中,您可能有一个如下所示的按钮:
<button onclick="window.external.HelloFromTheForm()">
Say hi to the form
</button>
所以关于你的问题“这是用来调用服务器端函数吗?”,你的表单不是“服务器端”,但它确实允许你调用表单的 C#/VB.NET 代码一个嵌入式网页。
关于c# - window.external有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10694341/