如何使用javascript过滤页面? [英] how to filter a page using javascript ?

查看:67
本文介绍了如何使用javascript过滤页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




假设我想过滤目标网页的内容,并且

在屏幕上显示一个更简单的页面。 br />

例如,让我们说目标网页上有很多链接,文字,图片,

表格等等,我想提出一个只包含链接的简单页面。

原始页面不是我的,也就是说,我不能在

记事本中编辑它并粘贴一些javascript在它。

所以,我想做的是在一个新的页面上写一些javascript,我将开发,这将以某种方式访问。或阅读目标页面,扫描

并查找所有链接,并将它们呈现给用户。


我的问题是,从javascript直接的方式是什么访问

目标页面?


我应该以某种方式将其加载到DOM对象中,然后行走。

树?


或者我应该以某种方式读取它的HTML作为文本字符串并解析它看起来

for anchor链接?


javascript中的哪些函数,方法,类,对象实现了目标

访问远程页面和查看的内容在它的内容。


指向我的方向,我会查找适当的对象,

方法,功能等。


谢谢! er*******@rcn.com



Let''s say I want to filter the contents of a target web page, and
present a simpler page on the screen.

For example, let''s say a target web page is full of links, text, images,
forms, etc. and I want to present a simple page containing just the links.
The original page is not "mine", that is, I can''t just edit it in
notepad and stick some javascript in it.
So, what I want to do is write some javascript on a new page that I''m
developing, that will somehow "access" or "read" the target page, scan
and find all the links, and present them to the user.

My question is, what''s a straightforward way from javascript to access
the target page ?

Should I be somehow loading it into a DOM object and then "walking" the
tree ?

Or should I somehow read it''s HTML as text strings and parse it looking
for anchor links ?

What functions, methods, classes, objects in javascript achieve the goal
of something accessing a remote page and "looking" at its contents.

Point me in a direction and I''ll look up the appropriate objects,
methods, functions etc.

Thanks ! er*******@rcn.com

推荐答案



我的问题的另一个措辞:


假设我希望我在html页面A中的javascript能够查看页面B的html

或DOM内容。我应该看一下javascript函数,类,方法

等实现这个目的吗?


Another wording of my question:

Suppose I want my javascript in html page A to be able to view the html
or DOM content of page B. What javascript functions, classes, methods
etc. should I look at for achieving this?


Eric Osman< 40 ************** @ rcn.com>写道:
Eric Osman <40**************@rcn.com> wrote:
我的问题的另一个措辞:

假设我希望我的html页面A中的javascript能够查看页面B的
html或DOM内容为实现这个目的,我应该考虑哪些javascript函数,类,
方法等?
Another wording of my question:

Suppose I want my javascript in html page A to be able to view the
html or DOM content of page B. What javascript functions, classes,
methods etc. should I look at for achieving this?




如果页面A和B在同一个域中,那么W3C DOM和

innerHTML扩展(支持哪里)是可能的,你是否只对

感兴趣的链接(正如你原来的帖子暗示的那样)然后

document.links集合将是查找

信息的地方。可能会将第二页加载到IFRAME中。


如果这两个页面来自不同的域,那么就把它忘记为

安全限制会阻止这样的行为(除了可能来自HTA或安全设置显着降低的本地浏览器,

只能在个人基础上真正适用。)


一般来说,你所描述的将更好地通过服务器端实现

脚本加载页面B并在任何安全上下文之外进行分析

(最好是获得许可)页面B)的所有者。


Richard。



If page A and B are within the same domain then the W3C DOM and the
innerHTML extension (where supported) are possibilities, is you are only
interested in links (as your original post implies) then the
document.links collection would be the place to look for the
information. Probably loading the second page into an IFRAME.

If the two pages originate in different domains then forget about it as
security restrictions will prevent such an action (except maybe from an
HTA or a local browser with significantly reduced security settings,
that is only really applicable on a personal basis).

Generally what you describe would be better achieved with a server side
script loading page B and analysing it outside of any security context
(and preferably with the permission of the owner of page B).

Richard.


Eric Osman写道:
Eric Osman wrote:

我的问题的另一个措辞:

假设我想在html页面A中使用我的javascript来查看页面B的html
或DOM内容。什么是javascript功能,类,方法
等我应该考虑实现这个目标吗?

Another wording of my question:

Suppose I want my javascript in html page A to be able to view the html
or DOM content of page B. What javascript functions, classes, methods
etc. should I look at for achieving this?



正如Richard Cornford提到的,如果这些网站不是来自同一个

域名,这将无效。你可以使用document.links来读取页面中所有的链接。


另外,假设A和B在同一个域上,你可以使用隐藏的IFRAME加载

数据页面,并使用javascript访问

IFRAME的文档树。


我过去曾使用过HTA(超文本应用程序),为了绕过域安全事件,但是_only_可以和IE一起使用。更多信息,请访问

msdn.microsoft.com。


Brian



As Richard Cornford mentioned, if these sites are not from the same
domain, this will not work. You can use document.links to read all of
the links in a page.

Also, assuming that A and B are on the same domain, you can load the
data page, using a hidden IFRAME, and use javascript to access the
IFRAME''s document tree.

I have used HTA (Hypertext Applications) in the past, in order to bypass
the domain security thing, but that _only_ works with IE. More info at
msdn.microsoft.com.

Brian


这篇关于如何使用javascript过滤页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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