Reputation: 1800
I have this HTML code in my website:
<iframe id="dado" src="other/maindome.html" width="100%" height="840px" frameBorder="0">
Your browser doesn't load this iframe.
</iframe>
When I use the function apri()
I correctly change the iframe src path.
function apri(dat) {
document.getElementById('dado').src= dat;
}
The page other/maindome.html
(for example) has a background called bgframe2.png
, and this page is showed inside the iframe. How can I change the maindome.html
background with bgframe5.png
? I must change maindome's opacity too.
<script>
$(document).ready(function(){
$('iframe').contents().find('body').css('backgroundImage', 'url_of_img.png');
$('iframe').contents().find('body').css('opacity', 0.8);
});"
</script>
I've googled aroud, I read some online stuff and I wrote the code above. By the way ,since I don't know jQuery, how could I call this function when I press a button (if it's correct)?
Upvotes: 1
Views: 668
Reputation: 8334
First this line is not correct :
$('iframe').contents().find('body').css('backgroundImage', 'url_of_img.png');
It should be :
$('iframe').contents().find('body').css('background-image', 'url(url_of_img.png)');
Answer to your comment :
HTML Button:
<input type='button' id='id_btn' />
JS code :
$(document).ready(function(){
$('#id_btn').click(function(){
$('iframe').contents().find('body').css('background-image', 'url(url_of_img.png)');
$('iframe').contents().find('body').css('opacity', 0.8);
});
});
Upvotes: 2
Reputation: 31106
<button id="btn">Hi</button>
<iframe id="dado" src="google.com" width="100%" height="840px" frameBorder="0">
Your browser doesn't load this iframe.
</iframe>
$('#btn').click(function(){
$('iframe').contents().find('body').css('background-image', 'url(http://lorempixel.com/400/200/)');
});
Upvotes: 1