Skip to main content

Microsoft Silverlight

Answered Question In beta2,all javascript event is blocked!!RSS Feed

(0)

nemiso
nemiso

Member

Member

3 points

9 Posts

In beta2,all javascript event is blocked!!

 

   I use many System.Windows.Browser namespace's class and method.

   For example ( HtmlPage.Window.Alert), (HtmlPage.Plugin.AttachEvent), etc....

    first, when I load a xap file on the server, it works quite well.

  but when I load a xap file on other site,(using object tag) it doesn't work.

  Is there any security issue??

   In addition, WebClient Class also doesn't work.

  I think all javascript access(including ajax) is blocked when I load a xap file on other site.

  Is there any other way to use other site's xap file without such limitations.

  I have a big problem.

 

 

swildermuth
swildermuth

Star

Star

8320 points

1,546 Posts

Re: In beta2,all javascript access is blocked!!

How is the XAP file hosted?  (e.g. Object tag, Silverlight.js, etc.)

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

Shawn Wildermuth
C# MVP, MCSD, Speaker and Author

Silverlight 3 Workshop
Miami, FL: Oct 12-14th
Portlant, OR: Dec 2-4th
Atlanta, GA: Dec 7-9th
http://silverlight-tour.com

nemiso
nemiso

Member

Member

3 points

9 Posts

Re: In beta2,all javascript access is blocked!!

I use Object tag like this.

////////////////////////////////////////////////

    <div id="silverlightControlHost">
  <object data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="100%" height="100%">
   <param name="source" value="ClientBin/MyProject.xap"/>
   <param name="onerror" value="onSilverlightError" />
   <param name="background" value="white" />
   <param name="EnableHtmlAccess" value="true" />
   <a href="http://go.microsoft.com/fwlink/?LinkID=108182" style="text-decoration: none;">
        <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
   </a>
  </object>
  <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
    </div>

/////////////////////////////////////////////////////////////////////

 

 this is auto-generated code.

 I tried a test in the local server.

 I changed source param, like this.

<param name="source" value="http://othersite.com/MyProject.xap"/>

and I added some codes in my project.

   Because of 'EnableHtmlAccess' param, 'HtmlPage.Window.Alert' or 'HtmlPage.Window.Confirm' methods work.

 but still 'HtmlPage.Plugin.AttachEvent("onmousewheel", this.HandleMouseWheel);' Command doesn't work.

 I can't get any event from 'HandleMouseWheel'  Handler.

 also, I cannot accept any event from 'WebClient' class. for example, 'OpenReadcompleted', 'DownloadStringCompleted', etc..

 

In addition, this's my Page.xaml.cs code.

        public Page()
        {
            InitializeComponent();

            HtmlPage.Plugin.AttachEvent("DOMMouseScroll", this.HandleMouseWheel);
            HtmlPage.Plugin.AttachEvent("onmousewheel", this.HandleMouseWheel);

            WebClient wc = new WebClient();
            wc.DownloadStringAsync(new Uri("{Some Path..}", UriKind.Relative));
            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
        }

        private void HandleMouseWheel(object sender, HtmlEventArgs args)
        {
            HtmlPage.Window.Alert("Wheel?!!");
        }
     
        void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
                HtmlPage.Window.Alert("down?");
         }

 

 

swildermuth
swildermuth

Star

Star

8320 points

1,546 Posts

Re: Re: In beta2,all javascript access is blocked!!

This does seem screwy.  Can you do a test for me to make sure its not in your code?  Do you have access to the DeepZoom composer?  There is an option to make a sample Silverlight site (and it uses the mousewheel hookups to do mouse wheel zooming). If you create a quite DeepZoom example and see if that works (it does for me), it might point at what the real issue is and if it is, in fact, a bug.

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

Shawn Wildermuth
C# MVP, MCSD, Speaker and Author

Silverlight 3 Workshop
Miami, FL: Oct 12-14th
Portlant, OR: Dec 2-4th
Atlanta, GA: Dec 7-9th
http://silverlight-tour.com

Sergey Volk MSFT
Sergey V...

Participant

Participant

788 points

98 Posts

Microsoft
Answered Question

Re: In beta2,all javascript event is blocked!!

 Hi,

I think I understand why you are having this problem. There are actually two parameters for allowing communication between cross-domain XAP file and host HTML page. Setting EnableHtmlAccess=true on object tag allows CLR (managed code) to invoke javascript methods / event handlers (so you can invoke HtmlPage.Window.Alert, etc). But there is one more parameter - ExternalCallersFromCrossDomain, which must be set if you want to allow javascript code to invoke methods in managed code. Try adding ExternalCallersFromCrossDomain='FullAccess' attribute to the root node of AppManifest.xaml file inside your XAP. This should fix your problem.

In cross-domain XAP scenarions, by default EnableHtmlAccess=false and ExternalCallersFromCrossDomain='NoAccess' (for security reasons).

If this answers your question, please click on "Mark as Answer" on this post.

nemiso
nemiso

Member

Member

3 points

9 Posts

Re: Re: In beta2,all javascript event is blocked!!

Thank you. you are right. have a good day.

nemiso
nemiso

Member

Member

3 points

9 Posts

Re: Re: In beta2,all javascript access is blocked!!

thank you for your concern. I often look around your site. you are really good teacher. ^^

have a good time.

Alex Little
Alex Little

Member

Member

2 points

1 Posts

Re: In beta2,all javascript event is blocked!!

Where do these two parameters go.  Im not sure where to put them.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities