从IFrame中读取document.links [英] Reading document.links from an IFrame

查看:131
本文介绍了从IFrame中读取document.links的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:
只需简单介绍一下这个程序的性质。此程序的目的是用于网络库存。将不同的链接和其他内容绘制成一种层次结构。我有麻烦的是从IFrame中的网页上拉一个链接列表。






我感觉到这一个会咬我的。 (其他帖子表示与xss和域控件的相关性)



我只是尝试使用javascript和iframe。基本上我有一个面板,里面有一个IFrame,去你想要的任何网站。我正在尝试从iframe中的网页生成链接列表。它的严格只读。



然而,我不断反对许可被拒绝的问题。



我明白这是停止跨站点脚本攻击,分辨率似乎是将文档域设置为主机站点。
拒绝JavaScript权限。如何允许跨域脚本在受信任的域之间?



但是,如果我想从站点到站点,我不认为这将工作。 p>

我的代码到目前为止,很简单:

  function getFrameLinks ()
{
/ *你们都可以忽略这个。这是因为在框架内有一个框架。它应该没有影响他的方案。只需从'contentFrameElement'开始阅读* /


//忽略这个
var functionFrameElem = document.getElementById(function-IFrame);
console.log(element by id parent frame);
console.log(functionFrameElem);
var functionFrameData = functionFrameElem.contentDocument;
console.log(Element data);
console.log(functionFrameData);

//获取内容并将其转换为文档
var contentFrameElem = functionFrameData.getElementById(content-Frame)
console.log(contentFrameElem);
var contentFrameData = contentFrameElem.contentDocument;
console.log(contentFrameData);

//获取链接
// var contentFrameLinks = contentFrameData.links;
var contentFrameLinks = contentFrameData.getElementsByTagName('a');






目标:好的,因为这是非法的非常类似于XSS。有人可能会指出如何本地存储文档的解决方案。在框架内部页面访问document.link时,我似乎没有任何问题。



可能是某种缓存的临时数据库。解决方案越简单越好。

解决方案

您可能有兴趣使用 YQL(Yahoo查询语言)从远程URL中检索筛选结果​​..



检索 yahoo.com域中的所有链接的示例


EDIT: Just a quick mention as to the nature of this program. The purpose of this program is for web inventory. Drawing different links and other content into a type of hierarchy. What I'm having trouble with is pulling a list of links from a webpage within an IFrame.


I get the feeling this one is gonna bite me hard. (other posts indicate relevance to xss and domain controls)

I'm just trying something with javascript and Iframes. Basically I have a panel with an IFrame inside that goes to whatever website you want it to. I'm trying to generate a list of links from the webpage within the Iframe. Its strictly read only.

Yet I keep coming up against the permission denied problem.

I understand this is there to stop cross site scripting attacks and the resolution seems to be to set the document domain to the host site. JavaScript permission denied. How to allow cross domain scripting between trusted domains?

However I dont think this will work if I'm trying to go from site to site.

Heres the code I have so far, pretty simple:

function getFrameLinks()
{
/* You can all ignore this. This is here because there is a frame within a frame. It should have no effect ont he program. Just start reading from 'contentFrameElement'*/


//ignore this
var functionFrameElem = document.getElementById("function-IFrame");
console.log("element by id parent frame ");
console.log(functionFrameElem);
var functionFrameData = functionFrameElem.contentDocument;
console.log("Element data");
console.log(functionFrameData);

//get the content and turn it into a doc
var contentFrameElem = functionFrameData.getElementById("content-Frame")
console.log(contentFrameElem);
var contentFrameData = contentFrameElem.contentDocument;
console.log(contentFrameData);

//get the links
//var contentFrameLinks = contentFrameData.links;
var contentFrameLinks = contentFrameData.getElementsByTagName('a');


Goal: OK so due to this being illegal and very similar to XSS. Perhaps someone could point out a solution as to how to locally store the document. I dont seem to have any problems accessing document.links with internal pages in the frame.

Possibly some sort of temp database of cache. The simpler the solution the better.

解决方案

You might be interested in using the YQL (Yahoo Query Language) to retrieve filtered results from remote urls..

example of retrieving all the links from the yahoo.com domain

这篇关于从IFrame中读取document.links的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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