javascript in SL 2.0 projects
Last post 05-08-2008 1:33 AM by Allen Chen – MSFT. 3 replies.
Sort Posts:
05-02-2008 8:19 PM
javascript in SL 2.0 projects

I am moving my application from SL 1.1 to SL 2.0.

In SL1.1 there were javascript - TestPage.html.js where the silverlight frame was being launched and we could hook

our javascript functions. But now in SL 2.0 project, I don't see any javascript file at all. How do I hook all my javascript functions.

In SL1.1 we had this piece of code that is not present in SL2.0 or I am missing the file where it is there - Please let me know. Thanks.

/contains calls to silverlight.js, example below loads Page.xaml
function createSilverlight()
{
 Silverlight.createObjectEx({
  source: "Page.xaml",
  parentElement: document.getElementById("SilverlightControlHost"),
  id: "SilverlightControl",
  properties: {
   width: "100%",
   height: "100%",
   version: "1.1",
   enableHtmlAccess: "true"
  },
  events: {onLoad: getcontrl_Loaded}
 });
 
   
 // Give the keyboard focus to the Silverlight control by default
    document.body.onload = function() {
      var silverlightControl = document.getElementById('SilverlightControl');
      if (silverlightControl)
      silverlightControl.focus();
        
    }
}

tv12345

Joined on 10-05-2007
Posts 14
05-03-2008 4:24 AM
Re: javascript in SL 2.0 projects

Using the Silverlight control doesn't give you many hooks for that.  But if you use either the Silverlight.js to host your control or the <object> tags, in both cases you can set the onLoad event to a JavaScript function.

(If this has answered your question, please "Mark as Answer")

Shawn Wildermuth
C# MVP, MCSD, Speaker and Author

Silverlight 2 Workshop
May 12-14, 2008 - Atlanta, GA
May 28-30, 2008 - San Francisco, CA
http://www.silverlight-tour.com

swildermuth

Joined on 10-13-2003
Atlanta, GA
Posts 1,058
05-06-2008 1:02 AM
Re: javascript in SL 2.0 projects

i am sorry, i couldn't follow - can you please include some sample code.

what gives more control if Silverlight control will not? I am confused here.

thanks

tv12345

Joined on 10-05-2007
Posts 14
05-08-2008 1:33 AM
Re: javascript in SL 2.0 projects

Hi:

  You can find the Silverlight.js file in SDK. Please refer to:

http://msdn.microsoft.com/en-us/library/cc265155(vs.95).aspx

Regards

Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Allen Chen – MSFT

Joined on 03-16-2007
Posts 717