如何避免iframe嵌入代码? [英] How to avoid iframe embedding code?

查看:78
本文介绍了如何避免iframe嵌入代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要更改我用以下标记嵌入的文本的样式

I want to change the style of my text that I am embedding with the following markup

<iframe src="URL">

我的网页有一定数量的字符, HTML。我使用iframe嵌入的代码是:

My web page has a limited amount of characters that can be used up very fast with coding in CSS and HTML. The code I'm using the iframe to embed is this:

<style type="text/css">

body {
    color: black;
}

h1 {
    color: #FFFFFF;
}

h2 {
    color: rgb(255,255,255);
}

</style>

<h1>Hello World!</h1>

但是当我使用以下代码来嵌入它:

But when I'm using the following to embed it:

<iframe src="THE RAW URL of the code above" frameBorder="0">

...整个代码显示,而不仅仅是 Hello World! 在#FFFFFF。

...the whole code is showing, not just the Hello World! in #FFFFFF.

我在这里做错了什么?我只会嵌入 Hello World!,但我知道父页面上的CSS不会改变我放在iframe中的源的样式。

What am I doing wrong here? I would embed just the Hello World! but I know that the CSS on the parent page will not change the style of the source I'm putting in the iframe.

推荐答案

由于iframe用于嵌入HTML文档,因此您应该尝试使用完全有效的HTML作为外部文件。像这样:

Since the iframe is for embedding HTML documents, you should try using a fully valid HTML as your external file. Something like this:

<!DOCTYPE html>
<html>
<head>
  <title>iframe example</title>
</head>
<body>
  <style type="text/css">
    body {
        color: black;
    }

    h1 {
        color: #FFFFFF;
    }

    h2 {
        color: rgb(255,255,255);
    }
  </style>
  <h1>Hello World!</h1>
</body>
</html>

这篇关于如何避免iframe嵌入代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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