I have a WPF application containing a Frame control. The frame control displays the html content. The html page contains a JavaScript function which I want to call after html page is loaded on Frame and from the WPF code ? Is there a way I can call JavaScript method of html page loaded in WPF frame control and from within WPF code?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
You can't interact with the HTML inside of a frame. In order to interact with HTML, you can use WPF's WebBrowser control of .NET 3.5 SP1.
You can see in WebBrowser control in action in this video:
http://channel9.msdn.com/posts/AdamKinney/WPF-35-SP1-App-Model-with-Jennifer-Lee/
Use
<body onload="javascript:alert('hi its loaded. do what you want here');">
in your HTML page, say myhtmlpage.html.Then use a frame XAML control (
<Frame Name="myWpfFrame" Source="http://myurl/myhtmlpage.html">
) in your WPF code.This solution will work assuming you want to call the javascript only once and thats only after the HTML page is loaded.
If you want to call the js more than once, you can possibly set the source property of the frame control from code as and when you need... as in ..
myWpfFrame.Source = myWpfFrame.Source;
There's no access to the DOM, so it's a no go I'm afraid. If it's something you definately need then your best bet is probably to embed the WinForms WebBrowser control from System.Windows.Forms.