admin管理员组文章数量:1388853
I'm attempting to use an XBAP to acquire TWAIN Images but I'm not even getting that far. I can't seem to get the BrowserInteropHelper.HostScript to allow me to talk back to the javascript on the host page.
- I am running the XBAP in an iframe.
- I tried full trust (even though that should be a requirement).
- I'm testing on IE9, .NET Framework 4.0
- The BrowserInteropHelper.HostScript is not null, I can use the normal window methods, like .Close().
My code looks like this:
Index.html:
<p id="someP">My cat's breath smells like cat food.</p>
<script type="text/javascript">
function WorkDamnit() {
$('#someP').hide();
}
</script>
<iframe src="@Url.Content("~/XBAPs/WPFBrowserApplication1.xbap")" style="border: none;" width="500" height="500" />
Page1.xaml.cs:
private void Button_Click(object sender, RoutedEventArgs e)
{
if (BrowserInteropHelper.HostScript == null)
throw new ApplicationException("hostscript is null");
else
BrowserInteropHelper.HostScript.WorkDamnit();
}
I get:
System.MissingMethodException: Method '[object Window].WorkDamnit' not found.
New Info:
This scenario works properly from other PCs on the network and I found out why. IE9 has a setting turned on by default called "Display intranet sites in Compatibility View". This causes the page to render in "IE7 mode" and the javascript function is available from the XBAP. If I click Document Mode: (under the F12 developer tools console) and switch to IE9 mode then it no longer works (as above). On my own PC it uses IE9 mode by default (As it should) and it does not work unless I manually switch to IE7 mode.
I'm attempting to use an XBAP to acquire TWAIN Images but I'm not even getting that far. I can't seem to get the BrowserInteropHelper.HostScript to allow me to talk back to the javascript on the host page.
- I am running the XBAP in an iframe.
- I tried full trust (even though that should be a requirement).
- I'm testing on IE9, .NET Framework 4.0
- The BrowserInteropHelper.HostScript is not null, I can use the normal window methods, like .Close().
My code looks like this:
Index.html:
<p id="someP">My cat's breath smells like cat food.</p>
<script type="text/javascript">
function WorkDamnit() {
$('#someP').hide();
}
</script>
<iframe src="@Url.Content("~/XBAPs/WPFBrowserApplication1.xbap")" style="border: none;" width="500" height="500" />
Page1.xaml.cs:
private void Button_Click(object sender, RoutedEventArgs e)
{
if (BrowserInteropHelper.HostScript == null)
throw new ApplicationException("hostscript is null");
else
BrowserInteropHelper.HostScript.WorkDamnit();
}
I get:
System.MissingMethodException: Method '[object Window].WorkDamnit' not found.
New Info:
This scenario works properly from other PCs on the network and I found out why. IE9 has a setting turned on by default called "Display intranet sites in Compatibility View". This causes the page to render in "IE7 mode" and the javascript function is available from the XBAP. If I click Document Mode: (under the F12 developer tools console) and switch to IE9 mode then it no longer works (as above). On my own PC it uses IE9 mode by default (As it should) and it does not work unless I manually switch to IE7 mode.
Share Improve this question edited Nov 7, 2011 at 18:17 Luggage asked Oct 27, 2011 at 20:18 LuggageLuggage 1,8461 gold badge20 silver badges22 bronze badges6 Answers
Reset to default 3In IE9, window methods are available to you, so you could try setTimeout
BrowserInteropHelper.HostScript.setTimeout("WorkDamnit()",0);
Its due to IE security settings. IE by default blocks the scripts if page is opened from local drive. IE should display the warning message as "'To help protect your security, Internet Explorer has restricted...."
However you can change the settings
Check the checkbox "Allow active content to run in files on My Computer"
IE9 does not expose BrowserInteropHelper.HostScript
unless it is in patibility mode.
This is pretty far after the fact but I wanted to chime in because I've dealt with this problem and it's an ugly one.
As you have observed, the machines it runs on work because they are running in patibility mode. You can instruct IE9 to render your page using patibility mode by adding the following tag to your html documents:
<meta http-equiv="X-UA-Compatible" content="IE=8"/>
I'm confident in saying, adding this tag is your only 'solution.' I've spent weeks looking for a better one and this is the one I'm still stuck with.
For whatever reason the ScriptInteropHelper
is rife with problems in IE9. It hasn't gotten a lot of attention from Microsoft, likely because it's obscure functionality. That said, particularly because IE7 and IE8 have all sorts of quirks, it's extraordinarily annoying you have to run in patibility mode. There are a number of MSDN articles, for example this one and enter link description here that discuss the issue further.
If someone is still wondering about this problem, I got found out a solution. Basically from document object you can municate properly without any hacks in latest browsers and with HTML5 doctype.
I wrote a blog post that contains the codes and examples:
XBAP and Javascript with IE9 or newer - Solution for MissingMethodException problems
Quickly explained this works properly:
Javascript
document.ResponseData = function (responseData) {
alert(responseData);
}
C# XBAP
var hostScript = BrowserInteropHelper.HostScript;
hostScript.document.ResponseData("Hello World");
It can be then used to pass C# object to Javascript and used as "proxy" object. Check that blog post for details how that can be used.
BrowserInteropHelper.HostScript.setTimeout("WorkDamnit()",0);
its working but if i want to send callback functions to js how can i send object with setTimeout ?
when using for ie8 its working good
dynamic host = BrowserInteropHelper.HostScript;
host.sampleJSFunction(new CallbackObject(this));
本文标签: cCustom functions unavailable from BrowserInteropHelperHostScript in an XBAPStack Overflow
版权声明:本文标题:c# - Custom functions unavailable from BrowserInteropHelper.HostScript in an XBAP - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744627127a2616324.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论