Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug In beta2,all javascript event is blocked!!
7 replies. Latest Post by Alex Little on August 15, 2008.
(0)
nemiso
Member
3 points
9 Posts
06-13-2008 9:10 PM |
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
Star
8320 points
1,546 Posts
06-14-2008 4:55 AM |
How is the XAP file hosted? (e.g. Object tag, Silverlight.js, etc.)
06-14-2008 6:38 AM |
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?"); }
06-14-2008 5:38 PM |
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.
Sergey V...
Participant
788 points
98 Posts
06-14-2008 10:28 PM |
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).
06-18-2008 7:48 AM |
Thank you. you are right. have a good day.
06-18-2008 7:58 AM |
thank you for your concern. I often look around your site. you are really good teacher. ^^
have a good time.
Alex Little
2 points
1 Posts
08-15-2008 10:28 AM |
Where do these two parameters go. Im not sure where to put them.