是否可以获取网页的内容并进行动态更改? [英] Is it possible to get the content of a web page and change it dynamically?

查看:60
本文介绍了是否可以获取网页的内容并进行动态更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是:在某个时刻(例如,在OnLoad事件期间)扫描页面中的指令,采取措施实现这些指令,并从文本中删除指令,类似于Wikipedia的方式.会将{TOC}替换为动态生成的目录.我无法弄清楚的操作方法"的唯一部分是如何在页面的生命周期中获取并更改页面的文本.

现在,我正在使用Javascript做这种事情,但这依赖于我的用户启用了Javascript,这并不是一个安全的假设.另一种选择是使用外壳"页面,并在嵌入之前从我可以操纵的文本文件中加载内容.我认为,就地更改文本会更快,所以我想先尝试一下.

我的网站使用主/子结构,如果有什么区别.

那么,有什么建议吗?

What I want to do is: At some point (say, during the OnLoad event) scan the page for directives, take actions to implement those directives, and remove the directives from the text, similar to the way that Wikipedia will replace {TOC} with a dynamically generated table of contents. The only part of the "how to" I cannot figure out is how to get and then alter the text of the page during the page''s life cycle.

Right now I''m doing this sort of thing with Javascript, but that relies on my users having Javascript enabled, with is not a safe assumption. Another option would be to use a "shell" page and load the content from a text file that I can manipulate before embedding it. I think that changing the text in-place would be faster, though, so I''d like to try that first.

My site uses a master/child construction, if that makes any difference.

So, any suggestions?

推荐答案

你好,

您是否已经尝试过Response.Filter?

这是一个使用它的示例(用于对将是XHTML兼容的HTML源进行修改):
http://aspnetresources.com/articles/HttpFilters [
希望这会有所帮助.

最好的问候,
停止
Hello,

Have you allready tried the Response.Filter?

Here is an example of using it (used to do modifications to the HTML source that it will be XHTML-Compilant):
http://aspnetresources.com/articles/HttpFilters[^]

You can attach the filter anywhere you want in the page-cycle. If you want to process each request with the filter, you can attach the filter in the global.asax Application_BeginRequest event. If you do so, you need to check that the content-type is ''text/html''.

Hope this helps.

Best regards,
Stops


这篇关于是否可以获取网页的内容并进行动态更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆