如何通过IHTMLDocument2接口知道网页是否已经被修改过了?

深宇 2006-08-08 09:47:38
虽然有一个lastModified,但是无论有没有改变过,每次取值的结果都不一样.
通过什么方法可以知道内容是否改变呢?
...全文
609 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
深宇 2006-09-19
  • 打赏
  • 举报
回复
十分感谢!
我现在试试!
蒋晟 2006-09-17
  • 打赏
  • 举报
回复
<snip>
' *** Put this in your main class

Private m_ihcl As mshtml.IHTMLChangeLog
Private m_imc2 As mshtml.IMarkupContainer2
Private m_ihcs As mshtml.IHTMLChangeSink
Private m_cookie As UInt32

Private Sub CreateChangeLog()

' Get a handle to the current MarkupContainer
m_imc2 = DirectCast(AxWebBrowser1.Document,
mshtml.IMarkupContainer2)

' Create a new change sink
m_ihcs = New ChangeSink(Me)

' Create the change log
m_imc2.CreateChangeLog(m_ihcs, m_ihcl, 1, 1)

m_imc2.RegisterForDirtyRange(m_ihcs, m_cookie)

End Sub
</snip>

<snip>
Public Class ChangeSink

Implements mshtml.IHTMLChangeSink

Private m_Owner As Form1

Public Sub New(ByVal frm As Form1)
m_Owner = frm
End Sub

Public Sub Notify() Implements mshtml.IHTMLChangeSink.Notify

Static count As Integer = 0

count += 1

Debug.WriteLine("Notify: " & count)

End Sub

End Class
</snip>
深宇 2006-09-17
  • 打赏
  • 举报
回复
试验了一下,发现这个CreateChangeLog函数需要IHTMLChangeLog和IHTMLChangeSink类型的参数。
查了很多资料都不知道如何获取这两个参数。
能否给出一个简短的例子?
深宇 2006-09-17
  • 打赏
  • 举报
回复
我说的是编辑模式下的
蒋晟 2006-09-15
  • 打赏
  • 举报
回复
你说的修改是编辑模式下的修改还是在浏览模式下的修改?如果是编辑模式,可以用IMarkupContainer2::CreateChangeLog来获得
深宇 2006-09-15
  • 打赏
  • 举报
回复
假如是这样的话,那些HTML编辑器是如何得知网页是否被修改了呢?
蒋晟 2006-09-13
  • 打赏
  • 举报
回复
在IHTMLDocument2可用之前window.onload已经加载完毕了,这时候作的修改没办法知道
richmain 2006-09-13
  • 打赏
  • 举报
回复
BOOL CHtmlView::GetSource(CString& refString)
{
BOOL bRetVal = FALSE;
CComPtr<IDispatch> spDisp = GetHtmlDocument();

if (spDisp != NULL)
{
HGLOBAL hMemory;
hMemory = GlobalAlloc(GMEM_MOVEABLE, 0);
if (hMemory != NULL)
{
CComQIPtr<IPersistStreamInit> spPersistStream = spDisp;
if (spPersistStream != NULL)
{
CComPtr<IStream> spStream;
if (SUCCEEDED(CreateStreamOnHGlobal(hMemory, TRUE, &spStream)))
{
spPersistStream->Save(spStream, FALSE);

LPCTSTR pstr = (LPCTSTR) GlobalLock(hMemory);
if (pstr != NULL)
{
// Stream is always ANSI, but CString
// assignment operator will convert implicitly.

bRetVal = TRUE;
TRY
{
refString = pstr;
}
CATCH_ALL(e)
{
bRetVal = FALSE;
// DELETE_EXCEPTION(e);
}
END_CATCH_ALL

if(bRetVal == FALSE)
GlobalFree(hMemory);
else
GlobalUnlock(hMemory);
}
}
}
}
}

return bRetVal;
}
深宇 2006-09-12
  • 打赏
  • 举报
回复
主要是本地网页,但是网页修改后,并不一定会保存的,如果只是做了一些修改,但没有保存到本地,这时如何判断是否被修改过呢?
蒋晟 2006-09-11
  • 打赏
  • 举报
回复
如果是本地网页,你可以比较文件的修改时间
如果是远程网页,比较lastModified
wildmen 2006-09-11
  • 打赏
  • 举报
回复
参考: IPersistFile
yhmar007 2006-09-08
  • 打赏
  • 举报
回复
www.jundongelec.com
cenchure 2006-09-04
  • 打赏
  • 举报
回复
没有
深宇 2006-08-10
  • 打赏
  • 举报
回复
那没有什么方法可以知道内容是否改变了吗?
LegerWu 2006-08-09
  • 打赏
  • 举报
回复
也就只有IHTMLDocument2::lastModified Property这么一个属性可以知道了,有些网页是含有多个IHTMLDocument2指针的,比如含有Frame的网页,你取得的值也许并不是一个固定的文档指针的。

3,056

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧