When I load an HTML page into a WPF Frame element, it runs the JavaScript differently than if I load the same page into a Web browser like IE. Why is that, and is there any way to make Frame‘s behavior match the browser’s?
If I load the following HTML into a Web browser:
<!DOCTYPE html>
<script>
document.write('abc'[1])
</script>
it outputs b in Chrome, FireFox, Opera, and even IE. But if I load that same HTML into a WPF Frame:
<Frame Source="C:\Path\To\Page.htm" />
it outputs undefined instead.
Why the difference in behavior? I thought Frame was supposed to use Internet Explorer to render, but apparently it’s doing something different.
If I leave off the DOCTYPE line, then IE also outputs undefined (though none of the other browsers do), which suggests that IE is using a different version of JavaScript (!) when the page doesn’t declare itself to be HTML5. But then I would expect Frame to use the same logic, and clearly it does not — it uses the older, not-supporting-string-indexing version of JavaScript even when I do declare the page to be HTML5.
What’s going on to cause Frame to run the JavaScript differently than IE?
It uses a lower engine. I assume you tested it on IE9? Well, IE9 broke away from the ActiveX control-style web browser. You need to use
'abc'.charAt(0)instead ofabc[0].