transformNode后,用webbrowser直接用stream方式加载,css路径就不对了

ahao 2006-05-20 12:54:58
问题是这样的,如果我把transformNode后的内容保存为html文件,然后用webbrowser去navigate这个文件,是对的,因为html文件里有这句:
<link href="2.css" rel="stylesheet" type="text/css" />
这个css文件和生成的html文件在一个目录下.
但如果我不保存html文件,直接用webbrowser显示transformNode后的内容,发现css没有起作用,
如果我把<link href="2.css" rel="stylesheet" type="text/css" />
里的2.css改成绝对路径,就对了.
因为我不想hardcopy一个绝对路径,也不想动态修改xml和xsl文件,应该怎么办?
...全文
357 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ahao 2006-05-22
  • 打赏
  • 举报
回复
多谢,第一个可以,第二个还没试
蒋晟 2006-05-22
  • 打赏
  • 举报
回复
The easiest way to do this is to embed a <base> tag into the generated
HTML. You don't have to save it to disk, or make visible to the user,
just feed it in the stream with the rest of the content.

Another way is to write a custom implementation of IMoniker interface.
You only need a non-trivial implementation of two methods: BindToStorage
should return the IStream with your HTML content, and GetDisplayName
should return the base URL you want to use to resolve relative links.
You then use IPersistMoniker to feed the content into MSHTML using this
custom implementation, instead of IPersistStreamInit. Disclaimer: I have
not done this myself, but I've seen people reporting successful use of
this technique.

Changed your LoadFromStream method to QI on the WebBrowser Document for
IPersistMoniker then pass your implementation of IMoniker that
implemented BindToStorage and GetDisplayName. In BindToStorage you simply use
a TStreamAdapter and return the stream.
ahao 2006-05-20
  • 打赏
  • 举报
回复
没错,我就是希望能找到办法告诉webbrowser默认路径是什么.

另外,我试了在显示前SetCurrentDirectory到css所在的路径,也是没用的
cpio 2006-05-20
  • 打赏
  • 举报
回复
如果不保存为HTML文件再打开

浏览器不知道路径啊

浏览器就是通过HTML文件的路径来定位相对路径的

不知道还有没有其它方法设置浏览器的默认路径

3,055

社区成员

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

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