在 iframe 中重新渲染网站?
我想创建一个网站,用户基本上可以从 iframe 内浏览网络。问题是我希望能够更好地控制 iframe 中渲染的内容。具体来说,
- 我希望能够过滤掉图像或文本、禁用表单等。
- 我还希望能够收集反馈,例如用户单击了哪些链接。
问题 1:
使用标准后端脚本语言(如 php)以及前端 html 和 javascript 是否可以实现这一点?
问题 2:
我是否需要在渲染网站之前首先获取网站的源代码,然后进行任何必要的操作,最后以某种方式重新渲染它?
问题 3:
有人可以解释一下这里发生的编程流程吗(假设有可能)?
I want to make a site where there user can basically navigate the web from within an iframe. The catch is that I'd like to be able to have more control over what is rendered within the iframe. Specifically,
- I'd like to be able to filter out images or text, disable forms etc.
- I'd also like to be able to gather feedback such as what links the users clicked on.
Question 1:
Is this even possible using a standard back-end scripting language (like php), with html and javascript on the frontend?
Question 2:
Would I first need to grab the source of the site before it is rendered, then do whatever manipulation is necessary, and finally re-render it somehow?
Question 3:
Could somebody please explain the programming flow that would occur here (assuming its possible)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您可能希望在渲染之前获取网站的源代码(带有服务器端代码)。如果您尝试使用 JavaScript,可能会遇到跨站点脚本问题。您的 iframe 将加载像 render.php 这样的页面,并传递该页面的地址以呈现 os 查询字符串参数。然后使用正则表达式查找 render.php 从该地址下载的 HTML 中的元素。根据需要重写 HTML,然后将其全部写入 iframe。
如果您想跟踪人们的去向,请重写链接,以便将用户带到您控制的页面并重定向到目标站点。示例:页面中的链接需要转到 google.com。您可以将它们发送到 tracker.php?target=http://google.com。您控制 tracker.php 并可以记录此页面的每次加载,然后将用户重定向到目标站点。
更新:
另一种可能的解决方案是使用 Apache 或其他服务器来代理目标网站。有像 mod_proxy 这样的模块可以实现此目的。可能还有一些模块可以让您解析 HTML,或者您可以推出自己的模块。
我应该指出,如果您无法完全控制目标站点,那么即使为您的问题提供的最佳解决方案也会有些脆弱。您将需要大量的错误处理或警报。
I think you would probably want to grab the source of the of site (with server-side code) before rendering it. You might run into cross-site scripting issues if you try to use JavaScript. Your iframe would load a page like render.php and pass the address of the page to render os a querystring parameter. Then use regular expressions to find elements in the HTML that render.php downloads from the address. Rewrite the HTML as necessary and then write it all out to the iframe.
Rewrite links so that that the user is taken to a page you control and redirected onto a target site if you want to track where people are going. Example: a link in the page needs to go to google.com. You would send them to tracker.php?target=http://google.com. You control tracker.php and can log each load of this page and then redirect the user to the target site.
Update:
Another possible solution is to use Apache or other server to proxy the target website. There are modules like mod_proxy for this. There may also be modules that let you parse the HTML or you could roll your own.
I should point out that even the best solutions offered to your question will be somewhat brittle if you do not have full control over the target site. You will want to have lots of error handling or alerting.
你可以看看这个。它非常好地使用 iFrame,甚至可能使用它拥有的库。
You can have a look at this. It uses iFrame really well, and maybe even use the library it has.