Although silverlight is sufficient for developing various page types, we consider the following scenario: What should we do if we want to obtain the browser width? In silverlight, this method is not available for direct use, but we know how to use webpage special effects to get the browser width. I will introduce two methods to call javascript.
1. execute javascript in silverlight
First, add the namespace: system. windows. browser;
Htmlpage. window. eval ("alert ('javascript executed ')");
2. Call the javascript function on the host page:
For example, we have the following javascript Functions on the host page:
Function prompt (){
Alert ("executed host js ");
}
Add the following code to silverlight:
Scriptobject urivirtual = htmlpage. window. getproperty ("prompt") as scriptobject;
Urivirtual. invokeself ();
In this way, the prompt function on the host page is called.
About silverlight
Microsoft silverlight is a web front-end application development solution developed by microsoft. It is one of the main application development platforms for microsoft's rich internet application policies, provides Solutions for multimedia (including audio and video streams and sound streams) and highly interactive front-end applications in web applications using browser plug-ins. It is also a Microsoft ux (user experience) one part of the Strategy is Microsoft's attempt to clearly split and collaborate with art design and program developers to develop applications.