AS3 AIR:如何在渲染之前删除 HTMLLoader 中的 html 元素?

发布于 2024-12-22 21:27:25 字数 209 浏览 1 评论 0原文

我正在使用 Adob​​e Air 制作自定义网络浏览器。

我想添加一个 html 过滤器功能来禁用 javascript & iframe。

如果我可以在渲染之前获取 html 代码,我会使用正则表达式删除标签元素。

我想当 htmlloader 的 LocationChangeEvent 调度时我可以使用 htmlloader 进行一些操作。

I'm making a custom webbrower by Adobe Air.

I would like to add a html filter function that disable javascript & iframe.

If I can get html code before render, I would delete tag elements with regexp.

I guess I can something with htmlloader when htmlloader's LocationChangeEvent dispatch.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执手闯天涯 2024-12-29 21:27:27

Kim,您可以使用如下方式访问 HTML:

myHtmlLoader.window.document.childNodes[0].innerHTML

但您需要确保在加载文档之前不会访问它(见上文)否则将为空。

当我在加载一个简单文件时使用上面的代码时,我看到这样的:

hello world

如果你不能得到它与上述内容一起使用,请告诉我,我将尝试收集一些示例代码。

Kim, you can get to the HTML using something like this:

myHtmlLoader.window.document.childNodes[0].innerHTML

but you need to make sure you don't access it until the document in loaded (see above) otherwise it will be null.

When I use the above code while loading a simple file, I see this:

<body marginwidth="0" marginheight="0">hello world</body>

If you can't get it to work with the above, let me know and I'll try to drum up some sample code.

書生途 2024-12-29 21:27:27

您需要捕获 Event.HTML_DOM_INITIALIZE 在加载器上。此时,html 已加载,DOM 树已创建,脚本尚未启动。然后您可以从加载器获取 window 对象并修改其子层次结构(请注意,这不是使用正则表达式删除标签。)
您还可以加载 html,将其解析为文本,应用过滤器并将过滤后的文本再次设置为 html,但随后您将收到另一个 HTML_DOM_INITIALIZE 事件和损坏 html 的风险。当然,选择权在你。

You need to catch Event.HTML_DOM_INITIALIZE on loader. On this moment, html is loaded, DOM tree created, scripts not yet launched. Then you can get window object from loader and modify its children hierarchy (note that this is not deleting tags with regexp.)
You can also get loaded html, parse it as a text, apply filter and set filtered text to html again, but then you'll get another HTML_DOM_INITIALIZE event and risk of damaged html. The choice is yours, of course.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文