简体   繁体   English

<div>内容未加载<iframe>

[英]<div> content is not loading in <iframe>

HTML: HTML:

<html>
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0" />
    <link href="css/jquery.mobile-1.4.1.min.css" rel="stylesheet">
    <script src="js/jquery-1.11.0.min.js"></script>
    <script src="js/jquery.mobile-1.4.1.min.js"></script>
    <script src="js/index.js"></script>

</head>
<body>
    <div data-role="page" id="demo-page" data-url="demo-page">
        <iframe id="iframe1" src="" width="100%" height="300">
        </iframe>   
        <div role="main" class="ui-content" id="div-content">
            <h1>Panel responsive</h1>
            <p>This is a typical page that has two buttons in the header bar that open panels. The left panel has the push display mode, the right panel reveal. To make this responsive, you can make the page re-flow at wider widths. This allows both the panel menu and page to be used together when more space is available. This behavior is controlled by CSS media queries.</p>
        </div>
    </div>
</body>
</html>

JS JS

<script>
    $(document).ready(function(){
        $("#iframe1").attr('src','#div-content');
    });
</script>

Here my Jsfiddle Example 这是我的Jsfiddle示例

Here my problem is that I want to load only <div> content in <iframe> . 在这里,我的问题是我只想在<iframe>加载<div>内容。 But in my case when I load <div> content in <iframe> then extra content is loaded in <iframe> . 但对我来说,当我加载<div>内容<iframe>然后额外的内容加载<iframe>

If someone have any idea about this problem then please help me. 如果有人对这个问题有任何想法,请帮助我。

Try this: 尝试这个:

$('#iframe1').contents().find('html').html($('#div-content').html());

or 要么

$('#iframe1').contents().find('body').html($('#div-content').html());

Try this. 尝试这个。

$(document).ready(function(){
        $('#iframe1').contents().find('body').append($('#div-content'));
  });

Fiddle Demo 小提琴演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM