English 中文(简体)
为其它域域的 iframe 创建内容
原标题:Create content for iframe of other domain

对于我们的论文,我们需要开发一个AdJail方法的原型,它能防止恶意广告。 这种方法通过将广告脚本置于不同来源的影子页面中将其置于不同来源。 (受同一来源政策保护 ) 通过将原始页面的内容复制到影子页面,该标语只能访问出版商允许访问的内容。

The problem lies in creating the iframe for the shadowpage. Originally, we implemented this:

if (document.createElement && (iframe = document.createElement( iframe ))) {
        iframe.id = "shadowpage";
        iframe.name = "shadowpage";
        iframe.height = 1400; 
        iframe.width = 1400;
        document.body.appendChild(iframe);
        var shadowScript = document.createElement("script");
        shadowScript.src = "ShadowTunnelScript.js";
        iframe.contentDocument.body.appendChild(shadowScript);
        adUrl = adScript;
}

显然,这并不能提供同一来源政策的要求的担保,因为这一框架的起源与载有文件的页面的起源相同。

我们的替代方案是,将框架的弧码设置为有不同来源的页面:

if (document.createElement && (iframe = document.createElement( iframe ))) {
        iframe.id = "shadowpage";
        iframe.name = "shadowpage";
        iframe.height = 1400; 
        iframe.width = 1400;
        iframe.src = "http://***/AdJail/Shadowpage.html";
        //iframe.style.display = "none";
        document.body.appendChild(iframe);
}

但在这种情况下,我们原型的用户 需要在不同的服务器上 创建自己的影子。

我们的问题是:是否有可能以不同来源创建这样一个框架,以动态的方式生成这个框架的内容,使用户只需在不提供影子页的情况下调用图书馆即可。

也许这可以通过首先产生框架的内容,然后改变框架的起源而成为可能吗?

问题回答

您可以尝试设置文档. domain 的值或将 iframe 内容设置为数据uri :

var content=window.btoa( <html>(..)<script>document.domain= sandbox ;</script></html> );
iframe.src = "data:text/html;base64,"+content;




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签