欺骗URL在web浏览器 [英] Spoofing the URL in a WebBrowser
问题描述
比方说,我得到一些页面的源代码code(例如 http://example.com )。我现在想要写这篇源$ C $ C到web浏览器,使用类似:
Let's say I get the source code of some page (e.g. http://example.com). I now want to write this source code to a WebBrowser, using something like:
myWebBrowser.Navigate("about:blank");
myWebBrowser.Document.Write(sourceCode);
现在,让我们pretend上Example.com的主页上,有一个相对URL,例如:
Now, let's pretend that on the homepage of Example.com, there's a relative URL such as:
<img src="/logo.gif" />
web浏览器将尝试从加载约:空白/ logo.gif
。我想告诉web浏览器的当前地址是 http://example.com
,以便它使用 http://example.com /logo.gif
代替。
The WebBrowser will attempt to load it from about:blank/logo.gif
. I want to tell the WebBrowser that the "current address" is http://example.com
so that it uses http://example.com/logo.gif
instead.
直接写入web浏览器的URL属性将导致导航(),这将摆脱我写任何文字。
Writing directly to the Url property of the WebBrowser will cause a Navigate(), which will get rid of any text I wrote.
我找了其他元素,以及诸如样式有效的解决方案,JavaScript的(如&LT; SCRIPT LANGUAGE =文/ JavaScript的SRC =myscript.js&GT;
),链接等,而不仅仅是图像。
I am looking for a solution that works for other elements as well such as stylesheets, javascript (e.g. <script language="text/javascript" src="myscript.js">
), links, etc., not just images.
这可能吗?
推荐答案
您可以尝试插入&LT;碱基GT;
头部元素:
http://www.w3.org/TR/html4/struct /links.html#edef-BASE
You could try and insert a <base>
element in the head:
http://www.w3.org/TR/html4/struct/links.html#edef-BASE
如何插入标签取决于你使用的语言,但你的目标应该是在&LT直接获得基本标记; HEAD&GT;
,这样产生的来源写着:
How to insert the tag is dependent upon the language you're using but you should aim to get the base tag directly after the <head>
so that the resulting source reads:
<head><base href="http://example.com"/>
当然,如果已经有一个&LT;基地方式&gt;
文档中的元素,您应该删除
Of course, if there is already a <base>
element in the document, you should remove that.
这篇关于欺骗URL在web浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!