Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iframe中仅显示一个div(javascript、JQuery…)_Javascript_Jquery_Iframe_Html - Fatal编程技术网

在iframe中仅显示一个div(javascript、JQuery…)

在iframe中仅显示一个div(javascript、JQuery…),javascript,jquery,iframe,html,Javascript,Jquery,Iframe,Html,首先,我要说的是,我对完全不同的方法持开放态度 我已经和我本人一样: <div id="testloadlogin"> <iframe src="../security/login.aspx" width="400" height="500" scrolling="auto" frameborder="1"> [Your user agent does not support frames or is currently

首先,我要说的是,我对完全不同的方法持开放态度

我已经和我本人一样:

<div id="testloadlogin">
      <iframe src="../security/login.aspx" width="400" height="500"
             scrolling="auto" frameborder="1">
      [Your user agent does not support frames or is currently configured
      not to display frames. However, you may visit
      <a href="../security/login.aspx">the related document.</a>]
      </iframe>
</div>

[您的用户代理不支持帧或当前已配置
不显示框架。但是,您可以访问
]
正在加载iframe的页面有一个名为loginInnerBox的div。我只想显示loginInnerBox和其中的所有内容

有什么办法吗?我正在考虑使用Jquery或javascript来删除iframe加载的页面上的所有其他内容,但不知道如何访问它

为了清楚起见,我希望我的页面上iframe之外的所有内容都保持完整。我想要相当于说$.('testloadlogin').load('../security/login.aspx'#loginInnerBox),它将只获取loginInnerBox的html并将其放在testloadlogin div中。但是,我需要来自另一个页面的后端处理,该页面由iframe支持,但不受Jquery加载的支持

iframe加载的页面的标记为

<body>
    <div>
    </div>.......
    <div class="AspNet-Login" id="ctl00_CLPMainContent_Login1">
        <div id="loginInnerBox">
            <div id="loginCreds">
                <table>
                </table>
            </div>
        </div>
    </div>
    <div>
    </div>....
</body>

.......
....
你需要更多的信息吗

我试过这个,没有效果:

<div class="ui-corner-all" id="RefRes">
        <div id="testloadlogin">
        <iframe onload="javascript:loadlogin()" id="loginiframe" src="../security/login.aspx"
             scrolling="auto" frameborder="1">
      [Your user agent does not support frames or is currently configured
      not to display frames. However, you may visit
      <a href="../security/login.aspx">the related document.</a>]
      </iframe>
        </div>
    </div>
    <script type="text/javascript">
        function loadlogin() {
            $('<body>*', this.contentWindow.document).not('#ctl00_CLPMainContent_Login1').hide();
        }
    </script>

[您的用户代理不支持帧或当前已配置
不显示框架。但是,您可以访问
]
函数loadlogin(){
$('*',this.contentWindow.document).not('#ctl00_CLPMainContent_Login1').hide();
}
请注意,这只适用于从同一域()加载的iFrame

EDIT:这可能也会删除
loginInnerBox
的子项。在这种情况下,您可以尝试在以下情况之前克隆它:

var iframe   = $("iframe").contents(),
    loginBox = iframe.find("#loginInnerBox").clone();

iframe.find("*").remove();
iframe.append(loginBox);
类似的内容。

将此添加到
-elememt:

onload="$('body>*',this.contentWindow.document).not('#ctl00_CLPMainContent_Login1').hide();"
它将隐藏身体的每个孩子,除了#ctl00_CLPMainContent_Login1


如果#ctl00_CLPMainContent_Login1包含的内容多于loginbox,则必须使用pex发布的clone()建议。

使用jQuery,不仅可以加载URL的内容,还可以从该URL中加载特定的CSS选择器。这将是一个更干净的方法。是这样的

$("#area").load("something.html #content");

我不明白。“只显示方框”是什么意思?您希望其他内容发生什么变化?iframe之外的内容呢?对不起。iframe中的其余内容我希望消失。iframe外部的内容我希望保持完整。这将取决于iframe内部加载的页面的标记,如何做,因此请显示标记。发布了总体布局,如果您愿意,我可以发布while页面…希望它们来自同一域。他们现在是,只是希望他们不要改变周围网站的域名。我正在测试,它什么都没做。只是像以前一样在iframe中显示整个页面。。尝试是否可以从iframe内容中删除任何内容。如果
remove
在iFrame上不起作用,您可以切换到
$(el).hide()
?我尝试过:$('#loginInnerBox').remove();它没有移除iframe中的loginInnerBox$(“#loginInnerBox”).hide();具有与显示登录框相同的效果。重要的是,在访问内容之前必须触发iframe的加载事件。因此,如果loginbox ii中有div,则必须使用clone?当我在iframe中单击一个按钮时,当使用clone时是否会像不使用clone时一样执行相同的服务器端代码?javascript不关心服务器端代码,另一方面,服务器也不关心javascript。
$("#area").load("something.html #content");