PRB: Permission Denied Accessing Web Browser Control in HTMLID: Q176789
|
When scripting a WebBrowser control that has been embedded in an HTML page, attempts to use any standard WebBrowser Control methods or properties fail with a "Permission Denied" scripting error.
Because of cross-frame security restrictions, any attempt to access the WebBrowser control from script automatically fails after the control has been set to browse a page in a different security context from the page hosting the control.
Replace any references to the WebBrowser control with an IFRAME tag. The IFRAME, for all intents and purposes, functions in the same manner as the WebBrowser control and can be positioned on a page. See the MORE INFORMATION below for an example of how to do this.
This behavior is by design.
Please note that this article discusses only the use of the WebBrowser control directly in an HTML page with the <OBJECT> tag and script.
<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBScript>
<!--
Sub window_onload()
WebBrowser1.Navigate"
<LINK TYPE="GENERIC" VALUE="http://www.microsoft.com"">http://www.microsoft.com"</LINK>
end sub
Sub document_onmousedown()
WebBrowser1.Navigate "<LINK TYPE="GENERIC" VALUE="http://testserver1"">http://testserver1"</LINK>
end sub
-->
</SCRIPT>
<TITLE>WebBrowser Control in HTML</TITLE>
</HEAD>
<BODY>
<OBJECT ID="WebBrowser1" WIDTH=332 HEIGHT=276
CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
<PARAM NAME="ExtentX" VALUE="8784">
<PARAM NAME="ExtentY" VALUE="7303">
<PARAM NAME="ViewMode" VALUE="1">
<PARAM NAME="Offline" VALUE="0">
<PARAM NAME="Silent" VALUE="0">
<PARAM NAME="RegisterAsBrowser" VALUE="0">
<PARAM NAME="RegisterAsDropTarget" VALUE="0">
<PARAM NAME="AutoArrange" VALUE="1">
<PARAM NAME="NoClientEdge" VALUE="1">
<PARAM NAME="AlignLeft" VALUE="0">
</OBJECT>
</BODY>
</HTML>
When this example page is loaded in Internet Explorer 4.0 (IE4), the
"window_onload" event handler navigates the embedded WebBrowser control to:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub window_onload()
window.frames(0).location.href = "<LINK TYPE="GENERIC" VALUE="http://www.microsoft.com"">http://www.microsoft.com"</LINK>
end sub
Sub document_onmousedown()
window.frames(0).location.href = "<LINK TYPE="GENERIC" VALUE="http://testserver1"">http://testserver1"</LINK>
end sub
-->
</SCRIPT>
<TITLE>WebBrowser Control in HTML</TITLE>
</HEAD>
<BODY>
<IFRAME ID="TestFrame1" WIDTH=332 HEIGHT=276>
</BODY>
</HTML>
</CODE>
In this example, the event handler for "document_onmousedown" succeeds
because cross-frame security permits setting the src property but not
reading it.
For additional information about Cross-Frame Security, please see the
following article in the Microsoft Knowledge Base:
Q167796 "Permission Denied" When Scripting Across Frames
Additional query words:
Keywords : kbIE400 kbIE401 kbIE500
Version : WINDOWS:4.0,4.01,5.0
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: April 15, 1999