Mutual calls between child windows, parent windows, and Silverlight

Source: Internet
Author: User

In fact, the call between them is still very simple ~
Basics
1. The parent page calls Js in the Child page
First, create a child form. CopyCode The Code is as follows: var win
$ (Function (){
Root = $ ('# root'). Val (); // you can specify the root directory.
});
Function openplayer (ID, type, add ){
// This is used to limit that the same window can only pop up once.
// In fact, if the name in the window. Open parameter is the same, it will not be opened again.
// Parameters in window. Open can be found in other Article , There are many
If (WIN = NULL | win. Closed ){
Win = Window. open ('HTTP: // loaclhost/SL. aspx ', 'win', 'width = 870, Height = 650, Top = 1, Left = 0, scrollbars = 0, resizable = 0, status = 1', true );
}

So how to call it?Copy codeThe Code is as follows: This. Alert ('Hello world! ');
Win. Alert ('Hello world! ');
Win. onload = function () {This. Alert ('test ');};

as we all know, the first line is a prompt box in this window (this can be omitted generally ~)
actually, this and win point to the same type and different objects.
therefore, their methods are the same.
the second line is to pop up a prompt box code in the subwindow.
You can also write subform events in the parent form ~
the third row is used to display a prompt box in the parent window when the child form is loaded.
2. The child form calls the parent form
This is similar to the above. When the parent form opens a child form, you can access the parent form in this way
window. opener
This object is the parent form, directly call the corresponding letter Number
3. Use a subform to call a Silverlight function or object
. This is a detailed description of msnd in Chinese ~ Here, I will give you some of the main steps (the method for calling the Silverlight object will not be posted, which is included)
additional portal:
1. In Silverlight, add an attribute -- scriptablemember copy Code the code is as follows: // myscriptablemanagedtype. CS
using system. windows. browser;
namespace HB {
public class myscriptablemanagedtype {
[scriptablemember ()]
Public String mytoupper (string Str) {
return Str. toupper ();
}< br> [scriptablemember ()]
Public string name {Get; Set ;}< BR >}

2. Register this object in the constructorCopy codeThe Code is as follows: myscriptablemanagedtype SMT = new myscriptablemanagedtype ();
Htmlpage. registerscriptableobject ("myslapp", SMT );
// If this function is not a function in an external class but a function of the SL body, you can directly pass the this pointer.

3. Open the page where slverlight is located
In the Silverlight OBJECT tag, add the onload attribute with the value "pluginloaded.
The following example shows the HTML tag used for reference by the Silverlight control.Copy codeThe Code is as follows: <Object Data = "data: Application/x-silverlight-2 ,"
Type = "application/x-silverlight-2" width = "100%" Height = "100%">
<Param name = "Source" value = "clientbin/HB. xap"/>
<Param name = "onerror" value = "onsilverlighterror"/>
<Param name = "onLoad" value = "pluginloaded"/>
<! --... -->
</Object>

4. Add the JavaScript function of the pluginloaded Method to the existing script element on the page.
Use the gethost method to obtain reference to the Silverlight control. The following example demonstrates the JavaScript code of the pluginloaded method.Copy codeThe Code is as follows: <SCRIPT type = "text/JavaScript">
VaR slctl = NULL;
Function pluginloaded (sender, argS) {// html Version
Slctl = sender. gethost ();
Alert (slctl. content. myslapp. mytoupper ("test string "));
}
</SCRIPT>

4. Silverlight calls js in the subform
It is also an article on msdn ~ Portal:
This is super simple and straightforward:
Htmlpage. Window. Invoke ("methodname", argS );
The preceding parameter is the function name, and the following parameter is the parameter that needs to be input by the function.
Improve
5. When a child page is opened on the parent page, parameters are directly input to Silverlight.
This is mainly used during initialization.
In the first part, we opened the subwindow http: // loaclhost/SL. aspx.
At this time, we can use the get method to pass in some parameters such as http: // loaclhost/SL. aspx? Id = 1
Then access in Silverlight as follows:

String id = htmlpage. Document. querystring ["ID"];

6. How can I front the subwindow?
Silverlight application in my subpageProgramIt is actually a music player, and then sub-pages are generally minimized.
However, when MessageBox is displayed in the Silverlight application, it is still in the minimized state... This is unfriendly to users.
If you want to front the child window, you can only call the win. Focus () function in the parent window.
However, we only need to deal with it a bit. In the parent window, child window, and SL, we can achieve this goal.
So you can do this:
1. Write a function in the parent window called focus ()
Then call win. Focus ();
2. Write a function in the subwindow called focus ()
Call window. opener. Focus ()
3. Finally, if you want to bring the Silverlight application to the front, you can call the focus () function in the parent window or subwindow, or you can call the focus () function of the subwindow in Silverlight.

7. How can I determine that Silverlight has been loaded?
There are several ideas as follows:
(√) In the Silverlight application constructor, call the Js of the Child page or parent page (through the Child page). [This method is feasible, but it is slightly troublesome]
(×) Write the window. onload event in the subpage. [Silverlight may not be loaded when this event is triggered]
(√) Do you still remember this in step 3? <Param name = "onLoad" value = "pluginloaded"/> [Recommended Practices]
After this item is added, after Silverlight is loaded, the function name on the trigger subpage can be changed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.