设置 iframe 的内容 [英] Set content of iframe

查看:23
本文介绍了设置 iframe 的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下结构.

<p>Hello World !!</p>

<iframe id="myiframe";src='myiframeContent.html'></iframe>

并且我有以下带有 content 的 JavaScript 变量:

var s =

Test_Div

";

如何更改 id myiframe 和变量 s 的 iframe 的内容?

我试过了:

$(#myiframe").html(s);

这给了我一个非常不寻常的回报,它将当前页面的所有内容更改为VAR S例如:样式、背景等.

如何使用包含 HTML 的变量设置 iframe 的内容?

变量s的内容如下:

 <头><title>{page_name}</title><元名称=关键字"内容={page_meta_tags}";/><script src="/1.js"></script><script src="/2.js"></script><风格>h2{红色;}h1{红色;}身体{背景色:#f0eded;颜色:74f503;字体系列:Verdana,日内瓦,无衬线;背景:网址({getUrl});}</风格><身体>雅虎<div style="float:right">{pagecomment}</div><div id="blogstart";样式="><h1>我的博客</h1>{nextPrevPagination}{博客}{nextPrevPagination}

<p>我的页面名称:{page_name}</p><br/><p>该模板的名称</p><br/><p>此页面的开始日期:{page_date}</p><br/><label>地址</label><textarea>{page_address}</textarea><span>国家:{page_country} 州:{page_state}</span><p>页面城市:{page_city}页面密码{page_pincode}</p><a href="mailto:{page_email}">给我发电子邮件</a>{page_bio_title} 和 {page_bio_desc}<img src="{page_profile}";/>{page_avatar}<p>联系我:{page_mobile},{page_landline} </p><a href="http://www.facebook.com/{page_facebook_user}>我在 Facebook</a><a href=http://www.twitter.com/{page_twitter_user}"></a>

将此变量应用于 iframe 后,我得到了这样的 [通过萤火虫检查]
请注意,它没有 BODY ,Head 标签,但上面的 [var s] 有一个 BODY 标签.

<title>{page_name}</title><meta content="{page_meta_tags}";名称=关键字"><风格>h2{红色;}h1{红色;}身体{背景色:#f0eded;颜色:74f503;字体系列:Verdana,日内瓦,无衬线;背景:网址({网址});}</风格>雅虎<div style="float: right;">{pagecomment}</div><div style="";id="blogstart"><h1>我的博客</h1>{nextPrevPagination}{博客}{nextPrevPagination}

<p>我的页面名称:{page_name}</p><br><p>该模板的名称</p><br><p>此页面的开始日期:{page_date}</p><br><label>地址</label><textarea>{page_address}</textarea><span>国家:{page_country} 州:{page_state}</span><p>页面城市:{page_city}页面密码{page_pincode}</p><a href="mailto:{page_email}">给我发电子邮件</a>{page_bio_title} 和 {page_bio_desc}<img src="{page_profile}">{page_avatar}<p>联系我:{page_mobile},{page_landline} </p><a href="http://www.facebook.com/{page_facebook_user}>我在 Facebook</a><a href=http://www.twitter.com/{page_twitter_user}"></a>

解决方案

我设法做到了

var html_string="content";document.getElementById('output_iframe1').src = "data:text/html;charset=utf-8," + escape(html_string);

I have the following structure.

<div>
<p>Hello World !!</p>
</div>
<iframe id="myiframe" src='myiframeContent.html'></iframe> 

and I have the following JavaScript variable with content:

var s ="<html><head></head><body><div>Test_Div</div></body></html>";

How can I change the content of iframe with id myiframe with variable s?

I tried:

$("#myiframe").html(s);

Which giving me a very unusual return, it changes all the content of Current page to VAR S Ex : styles,background etc..

How can I set the content of an iframe with a variable that contains HTML?

The content of variable s follows:

 <html>
  <head>
    <title>{page_name}</title>
    <meta name="keywords" content="{page_meta_tags}" />
    <script src="/1.js"></script>
    <script src="/2.js"></script>
 <style>
   h2{
 
 color:red;} 

 h1{
 color:red;}

 body{
     
 background-color:#f0eded;
 color:74f503;
 font-family:Verdana, Geneva, sans-serif;
 background:url({getUrl});}
  </style> 
  </head>
   
  <body>
    yahoo
    <div style="float:right">{pagecomment}</div>
    <div id="blogstart" style="">
      <h1>My Blog</h1>
      {nextPrevPagination}
      {blog} 
      {nextPrevPagination}
    </div>
    <p>My Page Name : {page_name}</p><br/>
    <p>Name of this template</p><br/>
    <p>Date started this page : {page_date}</p><br/>
    <label>Address</label>
    <textarea>{page_address}</textarea>
    
    <span>Country : {page_country} State :{page_state}</span>
    <p>page City : {page_city} Page Pincode {page_pincode}</p>
    <a href="mailto:{page_email}">Email me</a>
    {page_bio_title} and {page_bio_desc}
    <img src="{page_profile}" />
    {page_avatar}
    <p>Contact me : {page_mobile} , {page_landline} </p>
    <a href="http://www.facebook.com/{page_facebook_user}">I am on Facebook</a>
    <a href="http://www.twitter.com/{page_twitter_user}"></a>
  </body>
  
</html>

After applying this variable to the iframe I got like this [inspected through firebug]
Note that it doesn't have BODY ,Head tag, but the above one [var s] has a BODY tag.

<html>  
  
    <title>{page_name}</title>
    <meta content="{page_meta_tags}" name="keywords">
    
    
 <style>
   h2{
 
 color:red;} 

 h1{
 color:red;}

 body{
     
 background-color:#f0eded;
 color:74f503;
 font-family:Verdana, Geneva, sans-serif;
 background:url({url});}
  </style> 
  
    yahoo
    <div style="float: right;">{pagecomment}</div>
    <div style="" id="blogstart">
      <h1>My Blog</h1>
      {nextPrevPagination}
      {blog} 
      {nextPrevPagination}
    </div>
    <p>My Page Name : {page_name}</p><br>
    <p>Name of this template</p><br>
    <p>Date started this page : {page_date}</p><br>
    <label>Address</label>
    <textarea>{page_address}</textarea>
    
    <span>Country : {page_country} State :{page_state}</span>
    <p>page City : {page_city} Page Pincode {page_pincode}</p>
    <a href="mailto:{page_email}">Email me</a>
    {page_bio_title} and {page_bio_desc}
    <img src="{page_profile}">
    {page_avatar}
    <p>Contact me : {page_mobile} , {page_landline} </p>
    <a href="http://www.facebook.com/{page_facebook_user}">I am on Facebook</a>
    <a href="http://www.twitter.com/{page_twitter_user}"></a>
  </html>

解决方案

I managed to do it with

var html_string= "content";
document.getElementById('output_iframe1').src = "data:text/html;charset=utf-8," + escape(html_string);

这篇关于设置 iframe 的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆