[英]How to call javascript inside a WebBrowser control in winforms?
I want to call the javascript function 'Goto' like this : 我想像这样调用javascript函数'Goto':
javascript:Goto('DM_NEW_OBJECT.ASPX?DM_CAT_ID=2063&DM_PARENT_ID=2217&INPUTSELECTION=&DM_OBJECT_ID=0&PACK_ID=0&CASE_ID=0&mode=0&SITE=Default');
the function is located in the DefaultGeneral.aspx
page, and i need to call it from within a WebBrowser control 该函数位于
DefaultGeneral.aspx
页面中,我需要从WebBrowser控件中调用它
webBrowser1.Navigate("http://mySite/DefaultGeneral.aspx");
Do you have any idea ? 你有什么主意吗 ? Thank you.
谢谢。
Since you are using a WebBrowser object, I will assume that this is actually a Windows forms question and not an asp.net question. 由于您使用的是WebBrowser对象,我将假设这实际上是一个Windows窗体问题而不是asp.net问题。
You should look at the InvokeScript function of the web browser. 您应该查看Web浏览器的InvokeScript功能。
Let's say your webpage has the following function: 假设您的网页具有以下功能:
WITHOUT PARAMETERS: 没有参数:
<script type="text/javascript">
// Function Without Parameters
function JavaScriptFunctionWithoutParameters() {
outputID.innerHTML = "JavaScript function called!";
}
</script>
You would want to call it the following way: 您可能希望通过以下方式调用它:
this.webBrowser.InvokeScript("JavaScriptFunctionWithoutParameters");
WITH PARAMETERS: 带参数:
<script type="text/javascript">
// Function With Parameters
function Goto(someParameter) {
outputID.innerHTML = someParameter;
}
</script>
You would call it like this: 你会这样称呼它:
object[] param = new object[1];
param [0] = "DM_NEW_OBJECT.ASPX?DM_CAT_ID=2063&DM_PARENT_ID=2217&INPUTSELECTION=&DM_OBJECT_ID=0&PACK_ID=0&CASE_ID=0&mode=0&SITE=Default";
this.webBrowser1.Document.InvokeScript("Goto", param );
In C# you have to do something like this: 在C#中你必须做这样的事情:
Page.ClientScript.RegisterStartupScript(this.GetType(),"CallMyFunction","MyFunction()",true);
Or this: 或这个:
ClientScript.RegisterStartupScript(GetType(),"hwa","alert('Hello World');",true);
Check out this doc... 看看这个doc ...
http://msdn.microsoft.com/en-us/library/system.web.ui.page.clientscript(v=vs.110).aspx
Maybe ... put the javascript:Goto into the 也许......把javascript:转到
<body onload="">
... inside the quotes. ......在报价内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.