Transparent iframe over another iframe - html

What I'm trying to achieve is an iframe positioned over another iframe containing a PDF document - the first iframe should be transparent, and it should cover the iframe with PDF. I need this specifically for IE (9+).
The code I've tried so far:
<html>
<head>
<style>
</style>
</head>
<body>
<iframe src="iframeContent.html" frameborder="0" style="width: 1000px; height: 1000px; position: fixed; left:0px; top: 0px; background:transparent" allowTransparency="true"></iframe>
<iframe src='http://www.pdf995.com/samples/pdf.pdf' width="100%" height="300px" id="PDF" name="PDF"></iframe>
</body>
</html>
iframeContent.html:
<html>
<style type="text/css">
</style>
<body style="background: transparent">
</body>
</html>
However, the above doesn't work - the iframe is not transparent. Does anyone know how to solve this? As I said in the comments below, the solution posted below doesn't work with Adobe reader DC installed (if it works at all).

Try this code:
HTML 1
<!--Code for transparent iframe-->
<html>
<body style="background: none transparent">
<div> I am a crappy container on top of this boring PDF</div>
</body>
</html>
HTML 2
<!--Code for both iframes.
<html>
<head>
<style>
</style>
</head>
<body>
<iframe src="SO1.html" frameborder="0" style="width: 100%; height: 300px; position: fixed; left:0px; top: 0px;" allowtransparency="true"></iframe>
<iframe src='http://www.pdf995.com/samples/pdf.pdf' width="100%" height="300px" id="PDF" name="PDF"></iframe>
</body>
</html>
This positions the transparent iframe correctly on top of the PDF. Also, you had a syntax error for the attribute allowTransparency, it shouldn't have a capital T.

May be this will helps you
<html>
<head>
<style>
</style>
</head>
<body>
<iframe src="iframeContent.html" frameborder="0" style="width: 1000px; height: 1000px; position: fixed; left:0px; top: 0px; background:none transparent;" allowtransparency="true"></iframe>
<iframe src='http://www.pdf995.com/samples/pdf.pdf' width="100%" height="300px" id="PDF" name="PDF"></iframe>
</body>
</html>
iframecontent.html
<html>
<style type="text/css">
</style>
<body style="background:none transparent;">
</body>
</html>

For the iframe which you want to display transparent:
body{
opacity: 0.0;
background: transparent;
color: transparent;
}

I created two html files as below and it worked for me. I adjusted the width and height to 100% and it worked as you expect. Don't try with any jsbin etc instance and its not working there for security reasons as you load external site in iframe. Try with actual html file and load them in the browser which worked for me.
Html 1: pdf.html
<html>
<head>
<style type="text/css">
#outer {
position: fixed;
left: 150px;
top: 20px;
width: 100px;
z-index: 2;
}
#inner{
background-color: transparent;
}
.cover {
position: absolute;
border: none;
top: 0;
left: 0;
height: 100%;
width: 100%;
z-index: -1;
}
#pdf {
position: relative;
z-index: 1;
}
</style>
</head>
<body>
<div id="outer">
<div id="inner">
<iframe src="iframeContent.html" style="width:90px; height:70px; background-color: transparent;" frameborder="0" allowtransparency="true"></iframe>
</div>
<iframe class="cover" src="about:blank" allowtransparency="true"></iframe>
</div>
<iframe src='http://www.pdf995.com/samples/pdf.pdf' width="100%" height="600px" id="PDF" name="PDF" frameborder="0"></iframe>
</body>
</html>
Html 2: iframecontent.html
<html>
<body>
<h1 style="background-color:transparent;">Test</h1>
</body>
</html>

Try setting setting opacity: 0 on the outer iframe.
Using your modified code,
<iframe src="iframeContent.html" frameborder="0" style="opacity: 0; z-index: 2; width: 1000px; height: 1000px; position: fixed; left:0px; top: 0px; background:transparent" allowTransparency="true"></iframe>
<iframe src='http://www.pdf995.com/samples/pdf.pdf' width="100%" height="300px" id="PDF" name="PDF"></iframe>
You can also use z-index to manage stacking of elements. All elements default z-indez is 1. THose with higher values will appear on top of elements with a lower z-index.

Related

How to insert HTML/CSS code into an iframe?

So here's the code I have so far which basically renders an iframe that contains a URL.
<title>Test Layout</title>
<style type="text/css">
body, html
{
margin: 0; padding: 0; height: 100%; overflow: hidden;
}
#content
{
position:absolute; left: 0; right: 0; bottom: 0; top: 0px;
}
</style>
<div id="content">
<iframe width="100%" height="100%" frameborder="0" src="http://jcrew.com" />
</div>
What I want to do is instead of passing a URL into the iframe, I want to pass a HTML file (with CSS in it) and just display that. So I'll pass raw HTML (could be a String) and I want the iframe to contain that. Any ideas?
I'm also using rails for the rest of my web app. I'm working with a home.html.erb file.
Is there a way to do this without using Javascript? If not, how do I get Javascript to work in my Rails app?
Thanks.
try this it may help you
<iframe src="/pdfjs/web/viewer.html" style="width: 100%; height: 1100px; display:inline-block " scrolling="yes" webkitallowfullscreen mozallowfullscreen allowfullscreen frameborder="no"></iframe>
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2883.402927903083!2d10.394408315785519!3d43.72295585593467!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x12d591a6c44e88cd%3A0x32eca9b1d554fc03!2sLeaning+Tower+of+Pisa!5e0!3m2!1str!2str!4v1464959090343" width="600" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>

Two fixed iframe s (or div s) on the side

I can not see side2.html below the side1.html
page.html should scroll, side1.html and side2.html should be always visible, side1 above side2.
page.html
<!DOCTYPE html>
<html>
<head>
<title>page</title>
<style type="text/css">
<!--
body.container {
width: 100%;
height: auto;
}
.maintext {
float: right;
width: calc(100% - 210px);
}
iframe.side1 {
position: fixed;
float: left;
height: 600px;
width: 200px;
}
iframe.side2 {
position: fixed;
float: left;
top: 300px;
height: 300px;
width: 200px;
}
-->
</style>
</head>
<body>
<a name="topw" id="toppage"></a>
<div class="container">
<div class="maintext">
<a name="dic"></a><h3> Dict</h3><br/>
</div>
<iframe class="side1" src="side1.html" frameborder="0" />
<iframe class="side2" src="side2.html" frameborder="0" />
</div>
</body>
</html>
side1.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<a class="menu" target="_parent" href="page.html#dic" title="title" > title </a>
</body>
</html>
side2.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<a target="_blank" href="http://www.ubuntu.com" title="org">.org</a>
</body>
</html>
Or could I solve the problem just with div, without iframe. Something like here. But I can not make it work: side1 above side2
Position fixed needs positioned elements top/right/down/left to reference it's offset. float will not work on fixed elements.
I have also change the height and offset of the elements so they will fill the users screen no matter what size it is.
Also as #Sim pointed out iframes are now self closing and should have a proper closing tag.
body.container {
width:100%;
}
.maintext {
min-height:1080px; /*to simulate content*/
width:100%;
box-sizing:border-box;
padding-left:200px;
background:#ddd;
}
.side1,
.side2{
position: fixed;
left:0;
width:200px;
}
iframe.side1 {
top:0;
height:70%;
}
iframe.side2 {
top:70%;
height:30%;
}
<div class="container">
<div class="maintext">
<a name="dic"></a><h3>Middle Div</h3><br/>
</div>
<iframe class="side1" src="side1.html" frameborder="0"></iframe>
<iframe class="side2" src="side2.html" frameborder="0"></iframe>
</div>
you should close your iframes with </iframe>, because they aren't empty elements (to deal with browsers that do not support <iframe>, you could add a text between the opening and the closing tag of the iframe): https://www.w3.org/wiki/HTML/Elements/iframe
use top and left to position absolute when your element is position: fixed
I've modified your code (see comments):
<!DOCTYPE html>
<html>
<head>
<title>page</title>
<style type="text/css">
body.container {
width: 100%;
}
.maintext {
float: right;
width: calc(100% - 210px);
}
iframe.side1 {
position: fixed;
left: 0; /* use absolute positions when position fixed, not float */
top: 0;
height: 300px; /* 300px is enough, else it is behind your second iframe*/
width: 200px;
}
iframe.side2 {
position: fixed;
left: 0;
top: 300px;
height: 300px;
width: 200px;
}
</style>
</head>
<body>
<a name="topw" id="toppage"></a>
<div class="container">
<div class="maintext">
<a name="dic"></a><h3> Dict</h3><br/>
</div>
<!-- always add a closing tag to your iframes -->
<iframe class="side1" src="side1.html" frameborder="0" ></iframe>
<iframe class="side2" src="side2.html" frameborder="0" ></iframe>
</div>
</body>
</html>
I hope that solve your problem...

iFrame Height Auto (CSS)

I am having problems with my iframe. I really want the frame to auto adjust heights according to the content within the iframe. I really want to do this via the CSS without javascript. However, I will use javascript if I have too.
I've tried height: 100%; and height: auto;, etc. I just don't know what else to try!
Here is my CSS. For the frame...
#frame {
position: relative;
overflow: hidden;
width: 860px;
height: 100%;
}
And then for the frame's page.
#wrap {
float: left;
position: absolute;
overflow: hidden;
width: 780px;
height: 100%;
text-align: justify;
font-size: 16px;
color: #6BA070;
letter-spacing: 3px;
}
The page's coding looks like this...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" �� "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>...</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="header">
</div>
<div id="navigation">
home
about
fanlisting
100 reasons
letter
</div>
<div id="content" >
<h1>Update Information</h1>
<iframe name="frame" id="frame" src="http://website.org/update.php" allowtransparency="true" frameborder="0"></iframe>
</div>
<div id="footer">
</div>
</div>
</body>
</html>
Please note that the URL within the iframe is different then the website the iframe will be displayed on. However, I have access to both websites.
Can anyone help?
I had this same issue but found the following that works great:
The key to creating a responsive YouTube embed is with padding and a container element, which allows you to give it a fixed aspect ratio. You can also use this technique with most other iframe-based embeds, such as slideshows.
Here is what a typical YouTube embed code looks like, with fixed width and height:
<iframe width="560" height="315" src="//www.youtube.com/embed/yCOY82UdFrw"
frameborder="0" allowfullscreen></iframe>
It would be nice if we could just give it a 100% width, but it won't work as the height remains fixed. What you need to do is wrap it in a container like so (note the class names and removal of the width and height):
<div class="container">
<iframe src="//www.youtube.com/embed/yCOY82UdFrw"
frameborder="0" allowfullscreen class="video"></iframe>
</div>
And use the following CSS:
.container {
position: relative;
width: 100%;
height: 0;
padding-bottom: 56.25%;
}
.video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
Here is the page I found the solution on:
https://www.h3xed.com/web-development/how-to-make-a-responsive-100-width-youtube-iframe-embed
Depending on your aspect ratio, you will probably need to adjust the padding-bottom: 56.25%; to get the height right.
This is my PURE CSS solution :)
Add, scrolling yes to your iframe.
<iframe src="your iframe link" width="100%" scrolling="yes" frameborder="0"></iframe>
The trick :)
<style>
html, body, iframe { height: 100%; }
html { overflow: hidden; }
</style>
You don't need to worry about responsiveness :)
#SweetSpice, use position as absolute in place of relative. It will work
#frame{
overflow: hidden;
width: 860px;
height: 100%;
position: absolute;
}
hjpotter92
Add this to your section:
<script>
function resizeIframe(obj) {
obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
}
</script>
And change your iframe to this:
<iframe src="..." frameborder="0" scrolling="no" onload="resizeIframe(this)" />
It is posted Here
It does however use javascript, but it is simple and easy to use code that will fix your problem.
<div id="content" >
<h1>Update Information</h1>
<div id="support-box">
<div id="wrapper">
<iframe name="frame" id="frame" src="http://website.org/update.php" allowtransparency="true" frameborder="0"></iframe>
</div>
</div>
</div>
#support-box {
width: 50%;
float: left;
display: block;
height: 20rem; /* is support box height you can change as per your requirement*/
background-color:#000;
}
#wrapper {
width: 90%;
display: block;
position: relative;
top: 50%;
transform: translateY(-50%);
background:#ddd;
margin:auto;
height:100px; /* here the height values are automatic you can leave this if you can*/
}
#wrapper iframe {
width: 100%;
display: block;
padding:10px;
margin:auto;
}
https://jsfiddle.net/umd2ahce/1/
You have to use absolute position along with your desired height.
in your CSS, do the following:
#id-of-iFrame {
position: absolute;
height: 100%;
}
You should note that div tag behaves like nothing and just let you to put something in it. It means that if you insert a paragraph with 100 lines of text within a div tag, it shows all the text but its height won't change to contain all the text.
So you have to use a CSS & HTML trick to handle this issue. This trick is very simple. you must use an empty div tag with class="clear" and then you will have to add this class to your CSS. Also note that your have #wrap in your CSS file but you don't have any tag with this id. In summary you have to change you code to something like below:
HTML Code:
<!-- Change "id" from "container" to "wrap" -->
<div id="wrap">
<div id="header">
</div>
<div id="navigation">
home
about
fanlisting
100 reasons
letter
</div>
<div id="content" >
<h1>Update Information</h1>
<iframe name="frame" id="frame" src="http://website.org/update.php" allowtransparency="true" frameborder="0"></iframe>
<!-- Add this line -->
<div class="clear"></div>
</div>
<div id="footer">
</div>
<!-- Add this line -->
<div class="clear"></div>
</div>
And also add this line to your CSS file:
.clear{ display: block; clear: both;}
According to this post
You need to add the !important css modifier to your height percentages.
Hope this helps.

How to put iframe in to canvas

Hello i have a little question.
How can i put iframe with google map in to html ?
<canvas id="google_map" width="600" height="400">
<iframe width="600" height="390" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src=""></iframe>
</canvas>
you don't need to put map in the canvas try this....
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="width: 100%; margin-top: 50px;">
<iframe src="https://www.google.com/maps/embed?pb=!1m16!1m12!1m3!1d2965.0824050173574!2d-93.63905729999999!3d41.998507000000004!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!2m1!1sWebFilings%2C+University+Boulevard%2C+Ames%2C+IA!5e0!3m2!1sen!2sus!4v1390839289319" width="100%" height="200" frameborder="0" style="border:0"></iframe>
</div>
Unfortunately you can't place an iFrame inside the Canvas tag. You could however use relative position to overlay your iFrame over the canvas element:
<style type="text/css">
canvas {
width: 600px;
height: 400px;
}
iframe {
position: relative;
top: -400px;
width: 600px;
height: 400px;
}
</style>
<canvas></canvas>
<iframe src=""></iframe>
One thing I have to say though is that using frame's is normally a sign of inexperience in web development. Your use of them could likely be circumvented.

2 iFrames with different heights appear the same size when put on the same page

I have two separate <iframe> tags that are on the same page.
They are both in a <container> div and each <iframe> only shows a portion of each page.
The problem is when I try to put both of them on the same page, the bottom <iframe> is the same height as the top <iframe> even though I set the height of each <iframe> explicitly.
Even though each <iframe> is set to a different height, when I try to put both of them together, it messes things up.
Any help would be greatly appreciated. Thanks!
Here is my code:
HTML:
<div dir="ltr" style="text-align: left;" trbidi="on">
<title></title>
<style type="text/css">
<!--
#container{
width: 380px;
height: 360px;
overflow: hidden;
}
#container iframe {
width: 600px;
height: 475px;
margin-left: -15px;
margin-top: -90px;
border: 0;
}
-->
</style>
<div id="container">
<iframe height="200" scrolling="no" src="https://docs.google.com/spreadsheet/viewform?hl=en_US&formkey=dHJjVk94bExPMmxtaExmX1FSckpicGc6MQ#gid=0" width="600">
</iframe>
</div>
</div>
<div dir="ltr" style="text-align: left;" trbidi="on">
<title></title>
<style type="text/css">
<!--
#container {
width: 400px;
height: 65px;
overflow: hidden;
}
#container iframe {
width: 600px;
height: 675px;
margin-left: -20px;
margin-top: -350px;
border: 0;
}
-->
</style>
<div id="container">
<iframe height="200" scrolling="no" src="http://scores.espn.go.com/nfl/boxscore?gameId=310818027" width="600">
</iframe>
</div>
</div>
The value for the id attribute for any element in the same html document must be unique. You should not have two <div> elements with the id of container on the same page.
If you needed two elements to have similar styles, you could use the same class attribute on each of them.
In this case, you are looking to have different styles, so my recommendation would be to change the ids for each container div.
HTML:
<div dir="ltr" style="text-align: left;" trbidi="on">
<title></title>
<div id="spreadsheet">
<iframe scrolling="no" src="https://docs.google.com/spreadsheet/viewform?hl=en_US&formkey=dHJjVk94bExPMmxtaExmX1FSckpicGc6MQ#gid=0" width="600">
</iframe>
</div>
</div>
<div dir="ltr" style="text-align: left;" trbidi="on">
<title></title>
<div id="scores">
<iframe scrolling="no" src="http://scores.espn.go.com/nfl/boxscore?gameId=310818027">
</iframe>
</div>
</div>
CSS:
#spreadsheet{
width: 380px;
height: 360px;
overflow: hidden;
}
#spreadsheet iframe {
width: 600px;
height: 470px;
margin-left: -5px;
margin-top: -80px;
border: 0;
}
#scores {
width: 400px;
height: 65px;
overflow: hidden;
}
#scores iframe {
width: 600px;
height: 685px;
margin-left: -20px;
margin-top: -375px;
border: 0;
}
Note:
The CSS should ideally be placed in a separate document at a different URL and referred to in a <link> tag in the <head> section of your HTML document. If you need to have the styles inline, it is a best practice to include them in the <head> section of the document inside a <style> tag.
I've put an example of these changes in a jsfiddle.