【问题标题】:How to insert HTML/CSS code into an iframe?如何将 HTML/CSS 代码插入 iframe?
【发布时间】:2016-10-02 18:57:18
【问题描述】:

所以这是我到目前为止的代码,它基本上呈现一个包含 URL 的 iframe。

<title>Test Layout</title>
    <style type="text/css">
        body, html
        {
            margin: 0; padding: 0; height: 100%; overflow: hidden;
        }

        #content
        {
            position:absolute; left: 0; right: 0; bottom: 0; top: 0px; 
        }
    </style>

<div id="content">
<iframe width="100%" height="100%" frameborder="0" src="http://jcrew.com" /> 
</div>

我想要做的不是将 URL 传递到 iframe,而是传递一个 HTML 文件(其中包含 CSS)并显示它。所以我将传递原始 HTML(可能是一个字符串),我希望 iframe 包含它。有什么想法吗?

我还在我的网络应用程序的其余部分使用 Rails。我正在使用 home.html.erb 文件。

有没有办法在不使用 Javascript 的情况下做到这一点?如果没有,我如何让 Javascript 在我的 Rails 应用程序中工作?

谢谢。

【问题讨论】:

  • 您是否有理由在 iframe 中执行此操作,而不是仅将 html 呈现为字符串?

标签: html css ruby-on-rails iframe


【解决方案1】:

试试这个可能对你有帮助

<iframe src="/pdfjs/web/viewer.html" style="width: 100%; height: 1100px; display:inline-block "  scrolling="yes" webkitallowfullscreen mozallowfullscreen allowfullscreen frameborder="no"></iframe>

【讨论】:

  • 谢谢,不知道可以这样显示获取请求。
【解决方案2】:
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2883.402927903083!2d10.394408315785519!3d43.72295585593467!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x12d591a6c44e88cd%3A0x32eca9b1d554fc03!2sLeaning+Tower+of+Pisa!5e0!3m2!1str!2str!4v1464959090343" width="600" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 2018-06-04
    • 2015-07-22
    • 2012-01-09
    • 1970-01-01
    相关资源
    最近更新 更多