Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

In beta2,all javascript event is blocked!! RSS

7 replies

Last post Aug 15, 2008 02:28 PM by Alex Little

(0)
  • nemiso

    nemiso

    Member

    3 Points

    9 Posts

    In beta2,all javascript event is blocked!!

    Jun 14, 2008 01:10 AM | LINK

     

       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.

     

     

    HtmlPage webclient

  • swildermuth

    swildermuth

    Star

    8438 Points

    1547 Posts

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

    Jun 14, 2008 08:55 AM | LINK

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

    Shawn Wildermuth
    MVP, Speaker and Author

    Web Workshop (HTML5/CSS/MVC4)
    San Fran, CA - Mar 28-30, 2012
    Dallas, TX: Apr 29-May 1, 2012
    https://agilitrain.com/Workshop/Info/Web_Workshop
  • nemiso

    nemiso

    Member

    3 Points

    9 Posts

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

    Jun 14, 2008 10:38 AM | LINK

    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?");
             }

     

     

    silverlight webclient beta2 AttachEvent

  • swildermuth

    swildermuth

    Star

    8438 Points

    1547 Posts

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

    Jun 14, 2008 09:38 PM | LINK

    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.

    Shawn Wildermuth
    MVP, Speaker and Author

    Web Workshop (HTML5/CSS/MVC4)
    San Fran, CA - Mar 28-30, 2012
    Dallas, TX: Apr 29-May 1, 2012
    https://agilitrain.com/Workshop/Info/Web_Workshop
  • Sergey Volk MSFT

    Sergey Volk...

    Participant

    788 Points

    98 Posts

    Microsoft

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

    Jun 15, 2008 02:28 AM | LINK

     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

    3 Points

    9 Posts

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

    Jun 18, 2008 11:48 AM | LINK

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

  • nemiso

    nemiso

    Member

    3 Points

    9 Posts

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

    Jun 18, 2008 11:58 AM | LINK

    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

    2 Points

    1 Post

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

    Aug 15, 2008 02:28 PM | LINK

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