In beta2,all javascript event is blocked!!
Last post 08-15-2008 10:28 AM by Alex Little. 7 replies.
Sort Posts:
06-13-2008 9:10 PM
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.

 

 

nemiso

Loading...
Joined on 03-04-2008
Posts 5
06-14-2008 4:55 AM
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 2 Workshop
September 15-17, 2008 - Denver, CO
September 22-24, 2008 - New York, NY
http://www.silverlight-tour.com

swildermuth

Loading...
Joined on 10-13-2003
Atlanta, GA
Posts 1,195
06-14-2008 6:38 AM
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?");
         }

 

 

nemiso

Loading...
Joined on 03-04-2008
Posts 5
06-14-2008 5:38 PM
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 2 Workshop
September 15-17, 2008 - Denver, CO
September 22-24, 2008 - New York, NY
http://www.silverlight-tour.com

swildermuth

Loading...
Joined on 10-13-2003
Atlanta, GA
Posts 1,195
06-14-2008 10:28 PM
Marked as Answer
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.

Sergey Volk MSFT

Loading...
Joined on 03-22-2008
Posts 83
06-18-2008 7:48 AM
Re: Re: In beta2,all javascript event is blocked!!

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

nemiso

Loading...
Joined on 03-04-2008
Posts 5
06-18-2008 7:58 AM
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.

nemiso

Loading...
Joined on 03-04-2008
Posts 5
08-15-2008 10:28 AM
Re: In beta2,all javascript event is blocked!!

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

Alex Little

Loading...
Joined on 08-15-2008
Posts 1
Page view counter