I am hosting a web user control inside the xamWebHtmlViewer and need access to javascript methods that are in page that is run inside the xamWebHtmlViewer. Any ideas on how to access the page hosted within the HtmlViewer?
thanks in advance
Hello jmahoney,
The xamWebHtmlViewer doesn't have a public property referencing the loaded web page. It internally uses an IFRAME html element. So if you want to access the page's java script from your Silverlight application, you have to access the main page DOM. Then find the IFRAME element and access the page, and finally you'll have to get the javascript from the page.
It's a bit tricky but it's not impossible. Bear in mind that if you have more than one HtmlViewer it'll probably be difficult to distinguish the two IFRAMEs.
Regards,
Doychin Dochev
Hi Doychin,
Can you send a little more detail regarding this, I'm not sure which page DOM you are referring to. The page calling the silverlight control?
In my case I have default.html which calls my silverlight project. Within my project I'm loading an html page in the xamwebhtmlvewier, the html page loads a java applet. From a series of button click events in the silverlight page I want to pass variables to the java applet. Using HtmlPage.Window.Invoke I'm able to pass the variables to a javascript file that I use to send the values into the applet. But since I need the window to stay contained within a position in the page, HtmlPage.Window does not work for me.
I do have another HtmlViewer in my project.
Thanks,
Lisa
Lets assume that your main page that contains your silverlight application is called page1. When you add the HtmlViewer to your SL application and set SourceUri, an IFRAME html element is automatically added into your page1. The IFRAME will contain your second page - page2 that contains your Java Applet. From your Silverlight application you can invoke -
HtmlPage
.Window.Invoke(JS_FUNCTION_NAME, new object[] { parameter})
Your java script function should be in page1. The java scrip function will find the IFRAME and access the page2. After that it will access the applet and set the new parameters to it.
I've also tried replacing
Dim Viewer As FrameworkElement = sender.FindName("MyHTMLViewer1")
with
Dim Viewer As HtmlElement = Doc.GetElementById("_sl_historyFrame")
Which makes more sense since its referencing the htmlFrameElement.
But still no luck.
I know your busy but if you have anything for me on this can you please fire off a quick note. If I can't get this resolved with the XamWebHtmlViewer then I have to look into other methods. I have researched and tried everything I can think of so I must be misunderstanding something here.
Thanks so much,
Hello-
I did not find a solution for this. I ended up working thru a solution with the HTML content that was being hosted inside the control so I no longer needed the Silverlight Control to talk to the Javascript code.
Good luck.