Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

andrea cerqueira

iFrame com getElementById

Recommended Posts

Estou tentando pegar as informações de dentro de um iFrame e mandar para uma tabela em outra janela, na janela mãe mas não estou conseguindo, alguém pode me ajudar?

 

página mãe:

<table> <tr>   <td id="id_mae"><br /></td> </tr></table>

 

iframe da página filha:

<iframe id="id_editor" width="500" height="200"></iframe>

js na página filha para mandar o que está dentro do iframe para a página mãe:

<script>opener.document.getElementById('id_mae') = document.getElementById('id_editor');</script>

Compartilhar este post


Link para o post
Compartilhar em outros sites

troca o opener por parent//e bom...não está faltando o innerHTML ae não??

Compartilhar este post


Link para o post
Compartilhar em outros sites

troca o opener por parent//e bom...não está faltando o innerHTML ae não??

coloquei o innerHTML e ele não manda os valores pra página mãe, mas pelo menos dá sinal de vida e aparece escrito NULL onde deveria aparecer os valores, sobre trocar o opener por parent não acontece nada, nem aparece o null. :mellow:

Compartilhar este post


Link para o post
Compartilhar em outros sites

na página aberta no iframe tu coloca:parent.document.getElementById("id_mae").innerHTML = document.getElementById("id_editor").innerHTML;// assim você diz, +/-, q o conteúdo do elemento de Id igual a id_mae no documento pai (parent) é igual ao conteúdo do elemento com o id id_editor do documento atual

Compartilhar este post


Link para o post
Compartilhar em outros sites

Não funcionou, na verdade eu já testei de várias formas, com o parent não rola só rola mesmo com o opener, ele pegar oque eu escrever e coloca na tabela da página mãe corretamente, fiz isso com um texto pra testar, o problema é pegar os valores de dentro do iframe, e assi não vai de forma alguma, vou postar o código todo pra você dar uma olhada ok? é um editor html bem simples que peguei na net.

 

página mãe:

<script language=javascript><!--function popUpload(url) {window.open(url,'popUpload','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=550,height=350,screenX=150,screenY=150,top=150,left=150')}//--></SCRIPT><body>	  <form name="alteracao" method="post" action="<?php $PHP_SELF ?>">		<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">		  <tr>			<td width="400" align="center" bgcolor="#DCE4DF">			<input name="image" type="image" onClick="java script:popUpload('editor.php')" src="editar_foto.gif" align="middle">			<span class="fonte11VerdeBold">EDITOR</span></td>		  </tr>		  <tr>			<td align="center" id="id_mae"><br /></td>		  </tr>		  <tr>			<td width="400" align="center">			<input name="id" type="hidden" value="<?php echo $linha[id]; ?>">			<input type="image" src="inserir.gif" name="update" value="update" align="middle">			<span class="fonte11VerdeBold">ATUALIZAR</span> </td>		  </tr>		</table>	  </form>	  </body>

 

página filha:

<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Untitled Document</title><style type="text/css">TABLE#controle {background-color:#CCCCCC; padding:1px;}.classe_botao {height:18;BORDER-LEFT: #CCCCCC 1px solid;BORDER-RIGHT: #CCCCCC 1px solid;BORDER-TOP: #CCCCCC 1px solid;BORDER-BOTTOM: #CCCCCC 1px solid;}</style><script LANGUAGE="JavaScript">function botao_over(botao_fazer)		{		botao_fazer.style.backgroundColor = "#CCCCCC";		botao_fazer.style.borderColor = "#FFFFFF #666666 #666666 #FFFFFF";		}function botao_out(botao_fazer)		{		botao_fazer.style.backgroundColor = "CCCCCC";		botao_fazer.style.borderColor = "#CCCCCC";		}function botao_down(botao_fazer)		{		botao_fazer.style.backgroundColor = "#CCCCCC";		botao_fazer.style.borderColor = "#666666 #FFFFFF #FFFFFF #666666";		}function botao_up(botao_fazer)		{		botao_fazer.style.backgroundColor = "#CCCCCC";		botao_fazer.style.borderColor = "#CCCCCC";		}</script></head><body><?php$conteudo = addslashes("Texto automatico!");if(isset($_POST['enviar']))  {	echo "<script>opener.document.getElementById('id_mae').innerHTML = \"testando\";</script>";	echo "<script>self.close();</script>";  }?><table width="500" border="0" align="center" cellpadding="0" cellspacing="0"> <tr>   <td align="center"><!-- As duas linhas seguintes são como você submete a m***** - como uma variável escondida chamada "hidden_x" --><form method="post" action="<?php $PHP_SELF ?>" enctype="multipart/form-data"><input type="hidden" name="hidden_x" value=""><table width="500" border="0" cellspacing="0" cellpadding="0" id="controle">  <tr>	<td width="23" height="23"><div class="classe_botao" onClick='fazer("Bold")' onMouseOver="botao_over(this);" onMouseOut="botao_out(this);" onMouseDown="botao_down(this);" onMouseUp="botao_up(this);">	<img hspace="1" vspace=1 align=absmiddle src="img_editor/bold.gif" alt="Bold">	</div></td>	<td width="23" height="23"><div class="classe_botao" onClick='fazer("Italic")' onMouseOver="botao_over(this);" onMouseOut="botao_out(this);" onMouseDown="botao_down(this);" onMouseUp="botao_up(this);">	<img hspace="1" vspace=1 align=absmiddle src="img_editor/italic.gif" alt="Italic">	</div></td>	<td width="56" height="23"> </td>	<td width="23" height="23"><div class="classe_botao" onClick='fazer("InsertOrderedList")' onMouseOver="botao_over(this);" onMouseOut="botao_out(this);" onMouseDown="botao_down(this);" onMouseUp="botao_up(this);">	<img hspace="1" vspace=1 align=absmiddle src="img_editor/numlist.gif" alt="Numbered List">	</div></td>	<td width="23" height="23"><div class="classe_botao" onClick='fazer("InsertUnorderedList")' onMouseOver="botao_over(this);" onMouseOut="botao_out(this);" onMouseDown="botao_down(this);" onMouseUp="botao_up(this);">	<img hspace="1" vspace=1 align=absmiddle src="img_editor/bullist.gif" alt="Unordered List">	</div></td>	<td width="56" height="23"> </td>	<td width="23" height="23"><div class="classe_botao" onClick='fazer("JustifyLeft")' onMouseOver="botao_over(this);" onMouseOut="botao_out(this);" onMouseDown="botao_down(this);" onMouseUp="botao_up(this);">	<img hspace="1" vspace=1 align=absmiddle src="img_editor/left.gif" alt="Left Justify">	</div></td>	<td width="23" height="23"><div class="classe_botao" onClick='fazer("JustifyCenter")' onMouseOver="botao_over(this);" onMouseOut="botao_out(this);" onMouseDown="botao_down(this);" onMouseUp="botao_up(this);">	<img hspace="1" vspace=1 align=absmiddle src="img_editor/center.gif" alt="Center">	</div></td>	<td width="23" height="23"><div class="classe_botao" onClick='fazer("JustifyRight")' onMouseOver="botao_over(this);" onMouseOut="botao_out(this);" onMouseDown="botao_down(this);" onMouseUp="botao_up(this);">	<img hspace="1" vspace=1 align=absmiddle src="img_editor/right.gif" alt="Right Justify">	</div></td>	<td width="56" height="23"> </td>	<td width="23" height="23"><div class="classe_botao" onClick='fazer("Indent")' onMouseOver="botao_over(this);" onMouseOut="botao_out(this);" onMouseDown="botao_down(this);" onMouseUp="botao_up(this);">	<img hspace="1" vspace=1 align=absmiddle src="img_editor/inindent.gif" alt="Indent">	</div></td>	<td width="23" height="23"><div class="classe_botao" onClick='fazer("Outdent")' onMouseOver="botao_over(this);" onMouseOut="botao_out(this);" onMouseDown="botao_down(this);" onMouseUp="botao_up(this);">	<img hspace="1" vspace=1 align=absmiddle src="img_editor/deindent.gif" alt="Outdent">	</div></td>	<td width="56" height="23"> </td>	<td width="23" height="23"><div class="classe_botao" onClick='fazer("Cut")' onMouseOver="botao_over(this);" onMouseOut="botao_out(this);" onMouseDown="botao_down(this);" onMouseUp="botao_up(this);">	<img hspace="1" vspace=1 align=absmiddle src="img_editor/cut.gif" alt="Cut">	</div></td>	<td width="23" height="23"><div class="classe_botao" onClick='fazer("Copy")' onMouseOver="botao_over(this);" onMouseOut="botao_out(this);" onMouseDown="botao_down(this);" onMouseUp="botao_up(this);">	<img hspace="1" vspace=1 align=absmiddle src="img_editor/copy.gif" alt="Copy">	</div></td>	<td width="23" height="23"><div class="classe_botao" onClick='fazer("Paste")' onMouseOver="botao_over(this);" onMouseOut="botao_out(this);" onMouseDown="botao_down(this);" onMouseUp="button_up(this);">	<img hspace="1" vspace=1 align=absmiddle src="img_editor/paste.gif" alt="Paste">	</div></td>  </tr></table><iframe id="id_editor" width="500" height="200"></iframe><br /><br /><script>   id_editor.document.write("<?php    // aqui é onde ocorre o pré-carregamento do editor com o conteudo que você quiser   $explodeResult = explode("\r\n", $conteudo);   $total = sizeof ($explodeResult);   for ($count = 0; $count < $total; $count ++) {		 print($explodeResult[$count]);   }   ?>");		function fazer(editor) {		var tr = frames.id_editor.document.selection.createRange()		tr.execCommand(editor)		tr.select()		frames.id_editor.focus()		}		frames.id_editor.document.designMode = "on"</script><input type="Submit" name="enviar" value="enviar"></form>	</td>  </tr></table></body></html>

deixei a palavra testando pois foi o que fiz pra testar que o js tá mandando as informações pra página mãe ele só não tá pegando as infomações do iframe.

Compartilhar este post


Link para o post
Compartilhar em outros sites

bom eu consegui fazer tudo que estava dentro do iframe ir pra uma tabela na página mãe, só que acabei vendo que o que preciso é outra coisa, na verdade tenho que passar o código html (do que está dentro do iframe) pra uma textarea na página mãe, passar o iframe pra uma tabela foi, mas como eu faço pra pegar o código html do iframe? alguém sabe? http://forum.imasters.com.br/public/style_emoticons/default/assobiando.gif

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.