How to copy div from iframe to parent? (replicate) can be using ajax, jquery, javascript

0

I have an index.php which makes a post in conteudo.php, and takes the result and writes in the #contribed div within index.php.

Post:

<script type="text/javascript">


	$(this).on('load',function(){
		
		var dadosLink = 'nada';
		
		$.ajax({
			
			url:'conteudo.php',
			method: 'POST',
			data:{ dados:dadosLink},
			success: function(data)
				{
				
				$("#conteudo").html(data);
				
				}, 
				
				error: function(data)
				
				{
				$("#conteudo").html(data);
					}
			
		});
		
		});


	  </script>

In the content. php, I have:

<?php require_once('Connections/Gymo.php'); 
$aba = $_POST['dados'];

 if ($aba == "nada") {
	
	echo "
	<IFRAME name=Destaques frameBorder=0 style=\"overflow: scroll; height: 100vh; width: 100vw;\"  scrolling=auto src=\"inicio.php?dados=".$aba."&mercado=".$mercado."&email=".$email."\">
<div align=\"center\"></div>
</IFRAME>

	
	";
?>

inside the iframe inicio.php, I have:

<div class = "conteudo" id = "conteudo"> Quero replicar esta div para index.php com o mesmo id </div>

My question: How do I get the contents of this div contained in the iFrame to be passed to the div #contento contained in index.php, replacing their values, whatever they are?

This action would have to happen when activating the iframe's ajax function: "$ (this) .on ('load', function () ..."

    
asked by anonymous 15.10.2017 / 04:33

1 answer

1

First you need to get all the content that comes within the iframe, in which case it is your div .

You can do it this way:

var iframeContent = $(data).text(); // aqui vai retornar todo conteúdo dentro do iframe

After that, get all content that is within your div of iframe and put it in div of destination.

var divContent = $(iframeContent).text(); // aqui temos todo o conteúdo da div do iframe

$("#conteudo").empty().html(divContent); // limpando a div de destino e colocando o conteúdo da div do iframe.
    
15.10.2017 / 05:08