使用 URLConnection 时如何关闭 javascript 加载?
我希望在 Noscript 标签中加载网站的版本,因此连接必须看起来像已禁用 Javascript。
谢谢!
I'm looking to load the version of a site within the Noscript tags so the connection has to appear like it has Javascript disabled.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
UrlConnection 不需要对 noscript 标记执行任何操作,事实上它不能。 UrlConnection 只是获取内容,它不会尝试解析它并使用 JS/HTML 等执行任何操作。就其关心而言,它只是文本数据。
当 noscript 发挥作用时,就是您渲染内容的时候。
重新评论你的问题 - 当你禁用 JS 并转到该 URL 时,你仍然会得到与你请求带有 JS 的 URL 时相同的内容。如果您查看 Firebug 之类的 HTTP 响应,您会发现它总是相同的。渲染引擎正在做一些不同的事情,因此您需要查看应用程序渲染内容的位置,并查看是否可以在那里禁用 JS。
The UrlConnection will doesn't not need to do anything with the noscript tag, in fact it can't. UrlConnection just gets the content, it doesn't try to parse it and do anything with JS/HTML, etc. It's just text data as far as it cares.
When the noscript comes into play is when you go to render the content.
Re your comment to your question - when you disable JS and go to that URL you're still getting the same content as when you requested the URL with JS on. If you look at the HTTP response in something like firebug you'll see it's always the same. It's the rendering engine that is doing something different, so you need to look at where your app renders the content and see if you can disable JS there.
下载页面,解析它,然后查找如下所示的 iframe:
加载
src
属性中指定的 URL 以获取 noscript 版本。Download the page, parse it, and look for an iframe like this:
Load the URL specified in the
src
attribute to get to the noscript version.