Change iframe src and post date with javascript

Asked

Viewed 352 times

1

i have a script that changes the src of the iframe by java script (it has to be by this method), however I do not know how to send data by post only by get because it is only by putting the data in the url someone knows how to do this

<div id="overlayedt" >
    <iframe id="frameEditor" src="" style="position:absolute;width:100%;height:100%;background:white"></iframe>
</div>

Java script

function editfile(a,b,c){
    $("#frameEditor").attr('src','<?php echo $s; ?>/manager/editor/?a='+a+'&b='+b+'&c='+c+'',{aa:'oii'});
    $("#overlayedt").show();
}

have already tried to co-link the data via post with the {key:value} equal in the $.post() but nothing

  • What would be the problem of using get? If it really needs to be POST, a very simple way is a form with Hidden fields, whose target is iframe.

  • no get the data are more visible entente

  • and the following is that it is a file editor (type cpnael) so that you can understand better, the program lists folders and files and then if it is editable file the user can edit online in that case is passed to the function the file path and the name for that system. only that it is via get and quria only via post, I found nothing on the internet related to it

1 answer

3

Here’s a simple example of how to send a POST to a iframe:

HTML

<form id="formulario" action="http://httpbin.org/post" method="post" target="destino">
  <input type="hidden" id="campo" name="campo">
</form>
<iframe name="destino"></iframe>

JS

setInterval ( function(){
  document.getElementById("campo").value = Date();
  document.getElementById("formulario").submit();
}, 2000 );

See working on CODEPEN.

I used the date in the field as an example, to change the src and any other field, the logic is the same.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.