如何在没有javascript的情况下返回内容,如何隐藏iframe [英] How to hide an iframe if no content is returned without javascript

查看:174
本文介绍了如何在没有javascript的情况下返回内容,如何隐藏iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用特定大小的内容区域,但如果api的返回结果是,则我不想显示任何内容。



这是html的代码:

 < div class =myclass> 
< iframe frameborder =0src =http:// localhost:1000 / example>< / iframe>
< / div>

我正在调用一个有时可能返回null结果的API。
Javascript是关闭表。
我试着使用这样的css约束:

  .myclass {
max-width :1060px;
max-height:392px;

& > iframe {
min-height:0;
min-width:0;
max-width:1060px;
max-height:392px;
}

& > iframe:empty {
display:none;
}
}

css的行为是:iframe被隐藏所有的时间,虽然我有内容里面。
如果iframe如下:

 < div class =myclass> 
< iframe frameborder =0src =http:// localhost:1000 / example>
<! - notice white-space here - >
< / iframe>
< / div>

css不会将iframe视为空。

解决方案

我实际上是在没有javascript的情况下发生的。



但是你需要创建一个代理生成css。 / p>

如果下面不是一个可能性,那么所有的赌注似乎都关闭了。祝你好运!

 <!DOCTYPE html> 
< html lang =en>
< head>
< meta charset =UTF-8>
< title>标题< / title>
< style>
@import url('iframecheck.asp?url = http://www.example.com');
iframe {
width:1000px;
height:400px;
}
< / style>
< / head>
< body>
< iframe src =http://www.example.com>< / iframe>
< / body>
< / html>

iframecheck包含的代码检查url是否有空响应,如果它返回css像这样:

  iframe {
display:none;
}

这将自动覆盖其他 iframe style。



如果你这么做,请不要强制使用text / css内容类型头。

 <%response.ContentType =text / css%> 


I am trying to make a content area with a specific size, but I want nothing to be displayed if the returned result from the api is empty.

This is the code for the html:

<div class="myclass">
        <iframe frameborder="0" src="http://localhost:1000/example"></iframe>
</div>

I'm calling an API that sometimes might return a null result. Javascript is off the table. I've tried to use a css restraint like this:

.myclass {
max-width: 1060px; 
max-height: 392px;

  & > iframe {
      min-height: 0;
      min-width: 0;
      max-width: 1060px;
      max-height: 392px;
    }

   & > iframe:empty {
    display: none;
 }
}

The behavior for the css is: the iframe is hidden all the time, although I have content inside it. Also if the iframe is like this:

<div class="myclass">
        <iframe frameborder="0" src="http://localhost:1000/example">
        <!--notice white-space here-->
        </iframe>
</div>

The css will not see the iframe as empty.

解决方案

I actually made it happen without javascript.

But you need to create a proxy that generates the css.

If below is not a possibility then all bets seem off. Good luck!

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        @import url('iframecheck.asp?url=http://www.example.com');
        iframe {
            width:1000px;
            height:400px;
        }
    </style>
</head>
<body>
<iframe src="http://www.example.com"></iframe>
</body>
</html>

The iframecheck contains code that checks whether the url has empty response, if it does it returns css like this:

iframe {
    display:none;
}

Which will automatically override the other iframe style.

Don forget to force the text/css content type header if you do.

<%response.ContentType="text/css"%>

这篇关于如何在没有javascript的情况下返回内容,如何隐藏iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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