AS3 AIR:如何在渲染之前删除 HTMLLoader 中的 html 元素?
我正在使用 Adobe 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.
您需要捕获 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.