| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1936 人关注过本帖
标题:vb.net跨域访问疑虑。
只看楼主 加入收藏
zsdqxzxx
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2016-12-9
结帖率:33.33%
收藏
 问题点数:0 回复次数:1 
vb.net跨域访问疑虑。
Imports System
Imports System.Runtime.InteropServices
Imports mshtml
Imports SHDocVw
Namespace CodecentrixSample
    Public Class CrossFrameIE
        Const E_ACCESSDENIED As Integer = &H80070005
        Private Shared IID_IWebBrowserApp As Guid = New Guid("0002DF05-0000-0000-C000-000000000046")
        Private Shared IID_IWebBrowser2 As Guid = New Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E")
        ' Returns null in case of failure.
        Public Shared Function GetDocumentFromWindow(ByVal htmlWindow As IHTMLWindow2) As IHTMLDocument2
            If htmlWindow Is Nothing Then
                Return Nothing
            End If
            ' First try the usual way to get the document.
            Try
                Dim doc As IHTMLDocument2 = htmlWindow.document
                Return doc
            Catch comEx As COMException
                ' I think COMException won't be ever fired but just to be sure ...
                If (comEx.ErrorCode <> E_ACCESSDENIED) Then
                    Return Nothing
                End If
            Catch ex As System.UnauthorizedAcces***ception

            Catch ex As Exception
                ' Any other error.
                Return Nothing
            End Try
            ' At this point the error was E_ACCESSDENIED because the frame contains a document from another domain.
            ' IE tries to prevent a cross frame scripting security issue.
            Try
                ' Convert IHTMLWindow2 to IWebBrowser2 using IServiceProvider.
                Dim sp As IServiceProvider = htmlWindow.window
                Dim sp1 As IServiceProvider = CType(htmlWindow, IServiceProvider)
                ' Use IServiceProvider.QueryService to get IWebBrowser2 object.
                Dim brws As Object = Nothing
                sp.QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, brws)
                ' Get the document from IWebBrowser2.
                Dim browser As SHDocVw.WebBrowser = brws     '.IWebBrowser2 = brws
                Return browser.Document
            Catch
                Return Nothing
            End Try
        End Function
    End Class
    ' This is the COM IServiceProvider interface, not System.IServiceProvider .Net interface!
    _
    Public Interface IServiceProvider
        _
     Function QueryService(ByRef guidService As Guid, ByRef riid As Guid, ByRef ppvObject As Object) As Integer
    End Interface
End Namespace
 
使用方法:
Dim win As mshtml.IHTMLWindow2 = tmpframe.window
Dim doc As mshtml.IHTMLDocument2 = CodecentrixSample.CrossFrameIE.GetDocumentFromWindow(win)
MessageBox.Show(doc.body.innerHTML)
以上是网上搜索到的,但是,使用方法中的Dim win As mshtml.IHTMLWindow2 = tmpframe.window,tmpframe.window怎么用啊?
搜索更多相关主题的帖子: Return Nothing the End Dim 
2017-12-15 22:11
zsdqxzxx
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2016-12-9
收藏
得分:0 
高手呢?
2018-01-15 17:17
快速回复:vb.net跨域访问疑虑。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017652 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved