【发布时间】:2017-08-30 20:04:30
【问题描述】:
我希望允许用户将我的应用中的内容嵌入到他们的网站中。为此,我尝试运行以下解决方案:Allow users to embed my content into their sites (like blogs) -- rails 4
不幸的是,我遇到了 embed.js 中 iframe.src 的问题,因为它试图访问用户文件位置上的“嵌入”文件夹:
GET file:///.../embed/1 net::ERR_FILE_NOT_FOUND
#public/embed.js
window.onload = function() {
//Params
var scriptPram = document.getElementById('load_widget');
var id = scriptPram.getAttribute('data-page');
/iFrame
var iframe = document.createElement('iframe');
iframe.style.display = "none";
iframe.src = "embed/" + id;
document.body.appendChild(iframe);
};
如果我将 iframe.src 更改为指向我的应用的绝对 URL,例如“http://localhost:3000/embed”,然后我遇到了另一个错误:
Refused to display 'http://localhost:3000/embed/1' in a frame because it set
'X-Frame-Options' to 'SAMEORIGIN'.
对不起,如果这个问题看起来很随机,我正在使用 ruby-on-rails 迈出第一步。我保证会改进:)
【问题讨论】:
标签: ruby-on-rails iframe embed