How to edit the CSS of an iFrame?

2
  

I need to put a iFrame on my site that uses the following code:

<iframe allowtransparency="true" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no" src="http://www.cptec.inpe.br/widget/widget.php?p=3819&amp;w=h&amp;c=474647&amp;f=ffffff"height="180px" width="211px"></iframe>

How can I edit the CSS for content that is displayed?

I wanted to change some colors, backgrounds, etc ...

Would you like to add a new CSS sheet?

Or add CSS Incorporado same? Ex:

    <style rel="stylesheet" type="text/css">
    .classe { background: #000;
    }    
    #id { background: #FFF;
    }
    </style>
  

iFrame link: link

    
asked by anonymous 07.08.2014 / 08:29

2 answers

3

I've just done with jquery using a proxy, now I just work with the css and script to run the tabs, but that's what I leave with you :

jquery:

$('#divframe').load(
    'http://www.corsproxy.com/' +
    'www.cptec.inpe.br/widget/widget.php?p=3819&amp;w=h&amp;c=474647&amp;f=ffffff .tabtop',  function() {
         $('#divframe').html( $('#divframe').html().replace(new RegExp('src="', 'g'),'src="http://www.cptec.inpe.br/widget/'));});

HTML:

<divid="divframe"></div>

jsfiddle: link

EDIT: jsfiddle with the tabs script running: link

Alternative with proper proxy in PHP:

proxy.php (with only this content, and nothing else)

<?php
$cache_file = 'proxy_cache.html'; // nome do arquivo para salvar cache

if (!@file_exists($cache_file) || (time() - @filemtime($cache_file) > (60 * 60 * 6))) { // verificar se o cache expirou e fazer uma nova requisição ao cptec.inpe.br
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.cptec.inpe.br/widget/widget.php?p=3819&amp;w=h&amp;c=474647&amp;f=ffffff");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $retorno = str_replace('src="','src="http://www.cptec.inpe.br/widget/',curl_exec($ch));//adicionaroendereçoabsolutoatodosossrccurl_close($ch);file_put_contents($cache_file,$retorno);//salvarconteudonoarquivodecache}else{//cachenãoexpirouabriroconteudodoarquivosemnovarequisiçãoaocptec.inpe.br$retorno=file_get_contents($cache_file);}echo$retorno;//imprimiroconteudo?>
  

Thecontentbelowmustbeinanotherfile,alongwithcssand  everythingelse...exfile: test.html

jquery:

$('#divframe').load(
    'proxy.php .tabtop',  function() {
         $('#divframe .tab_content').hide();
         $('#divframe .tabs li:first').addClass('active');
         $('#divframe .tab_content:first').show();
         $('#divframe .tabs li').click(function(){
             $('#divframe .tabs li').removeClass('active');
             $(this).addClass('active');
             $('#divframe .tab_content').hide();
             $($(this).children('a').attr('href')).show();
         });
    });

HTML:

<div id="divframe"></div>
    
07.08.2014 / 13:59
1

By definition, iframe allows you to open an external document, whether it is on the same server or in others. Some javascript solutions can help you do what you want, but only if it's a document on the same server.

So in principle the answer is no.

But, you can create a copy of the external page on your server using PHP:

file_get_contents(/* string: url da página */)

And apply the CSS styles you want in the returned string, and you can even create a "version" of the original page on your server, with your own styles and scripts.

    
07.08.2014 / 13:57