I have a website with an iframe and the website has its own backdrop / overlay. My goal is to set z-index of a child element of iframe, so only this child element should be on top of the overlay. I have access to both website inside iframe and the top website.
I reproduced it in Plunkr, so my goal is to get the green box (modal) to the top.
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<iframe src="iframe.html" width="100%" height="500px" ></iframe>
<div class="backdrop">
Backdrop
</div>
</body>
Do you have an idea if it's possible? How?
You can't do what you want.
What you have is this:
document
body
iframe
- see document(2)
div[class="backdrop"]
document(2)
body
div[class="modal box"]
The two documents don't overlap and cannot interact with each other in such way. You can move your element to the top z-index within the iframe, but you cannot make the element "break out" of the iframe in the way you wish to achieve. You have to set the iframe itself to the top.
An alternative approach for you might be to use an ajax request, and then append the new element to the body, and style that to appear on top.
Related
I have say 6 aspx pages that I want to display within something like an Iframe so that when I look at the page I can see an array of controls that contain a web page.
But if I use an Iframe I cannot then size the content to the size of the Iframe although YouTube does resize the content so their must be a way to do so.
So, how would I go about making sure that the content fits the IFrame or is there a better way of doing this.
Also, ultimately I would like to go to the page if the control was clicked but I am not sure that the Iframe has a click event.
So, how would I go about doing that ?
If the contents of the iframe are on the same URL as the main page then you shouldn't have any security issues and you can add JavaScript to the content pages to pass the height of their content back to the main page. Same with click events: you can have some JavaScript call a function on the parent page.
Here's an example of a main and iframe content page. The content page has a button you can click that will resize the iframe based on the height of the content.
main.htm
<html>
<head>
<script type="text/javascript">
function resize1(h) {
document.getElementById("iframe1").height = h + 50;
}
</script>
</head>
<body>
<div>Test</div>
<iframe id="iframe1" border="1" height="100" src="iframe.htm" width="200">
</body>
iframe.htm
<html>
<body>
Resize iframe
<div id="content" style="background:Red;height:500;width:50px;">
Test content
</div>
</body>
You could adapt this to suit your needs. For example, the height could be set as soon as the iframe content loads by calling the function in the onload event of the iframe content page.
Note that any JavaScript functions you want to call on the main page must be in the HEAD section.
I want to select all DIVs in my page, including its child iframe.
I have two DIVs here but whenever i try and select them it only grabs the outer one.
<html>
<head></head>
<body>
<div class='xx'>blah</div>
<iframe id='x'>
<html>
<head></head>
<body>
<div class='xx'>blah2</div>
</body>
</html>
</iframe>
</body>
</html>
Is there any way for me to get both DIVs back?
var a = $('.xx');
alert(a.length); //only gives me 1 :(
My fiddle is here :
http://jsfiddle.net/7kvFw/
With only one call this is not possible at all. The iframe is another document so it is not accessable directly. You need to search in all frames seperatly.
By the way your example is not valid. A iframe is just a referece to another document you cannot put the content in the same html document. If you just care about a "box" with the option to scroll inside, just add the another div with the ablity to scroll. This would also allow you to get all .xx elements at once.
See also this fiddle.
I have these codes:
<html>
<head>
<title>Iframe</title>
</head>
<body>
SomePage<br/>
AnotherPage<br/>
<iframe src="" name="content" height="40%" width="100%"></iframe>
</body>
</html>
as you can see I have two links and one iframe,What i need is when I click SomePage.html link, I want the parent window reloads and then the SomePage.html will be loaded in the iframe, is this possible?, Thanks!
EDITED:
I have an Auto-Resizing iframe that only grows on heights and cannot shrink to smaller heights (well that's my problem here, All I want to achieve is the MasterPage like behavior in asp.net.
This is possible, you can use localStorage it's not cross fully browser. Quick Example.
$(document).ready(function(){
if(localStorage.frameURL) {
$("iframe[name=content]").attr('src', localStorage.frameURL);
}
$("[target=content]").click(function() {
localStorage.frameURL = $(this).attr('href');
window.location.reload();
});
});
I'm building my personal page, which is a computer with an iframe inside of it's screen with a dummy javascript terminal. My problem is that I can't get the iframe to scroll down while I keep writing on the terminal.
I've tried adding scrolling="yes" to the iframe and it doesn't work. I tried using $(document).scrollTop($(document).height()); in the iframed page and setting the height of the iframed page to 2000px... none of this worked.
This is the code of the page:
<html>
<head>
<style type="text/css">
body{
background-image:url('http://api.ning.com/files/B4MPF1W8yyhcpqgtcWbw-UuRX4aul676AQ0rB63HYNkXgQR06pGjZVwjKcwMxGgc/apple2c.big.jpg');
background-repeat:no-repeat;
}
#iframe {
position:relative;
padding-top:35px;
padding-left:144px;
}
</style>
</head>
<body>
<div id="iframe">
<iframe src="http://static.saezmedia.com/terminal/terminal/examples/rpc-demo.html" width="458" height="341" scrolling="auto"></iframe></div>
</body>
</html>
Thank you very much for your help.
In you main page: http://static.saezmedia.com/terminal/terminal/examples/rpc-demo.html you have the following css code:
jquery.terminal.css:13:
overflow:hidden;
this makes the scroll bar non visible. If you remove this the page is scrollable and then you have to automatically scroll to the bottom.
If you open it in another window, you won't be able to scroll it either.
That looks like an issue with the site.
However, you may be able to scroll it explicitly by fixing the width/height of the iframe and setting overflow auto on the containing div.
I'm not sure if this is even possible.
I've got the following code;
<iframe src="http://www.domain.com/content.html" width="200" height="50"></iframe>
Now, I would have assumed that would've hyper-linked the entire iFrame area, however it only hyperlinks the border.
Is it possible to hyperlink the entire iframe area?
no, that's not valid. you can't even reliably get a click event off of the element containing the iframe.
e.g.,
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#bob').click(function(e){
alert('hi');
});
});
</script>
</head>
<body>
<div id="bob" style="padding:100px;background:red;"><iframe src="http://www.google.com"></iframe></div>
</body>
</html>
notice that if you click the iframe, no alert fires - but if you click anywhere else (in red), it will. if this were otherwise, there'd be abuse...
What actually do you mean by "hyperlink the iframe"?
You could try to use an onclick event for the iframe, or position a div with an onclick and transparent background above the iframe. Another possibility is to set the a to display: block and position it above the iframe.