Auto Fill Input on another browser tab via script

4

Is there a script that sends the value of my input to the page input I open?

As the example below shows, I need to send the value "12345" to the XYZ page input as soon as I click on the link to open it, to speed up the search by code.

My site:

<div>
   <a href="www.paginaxyz.com.br">Consultar</a>
   <input id="CodigoConsulta" type="hidden" value="12345" />
</div>

XYZ Page:

<div>
    <label>Código: </label>
    <input id="Codigo" type="text" value="" <--receber-- "12345" />
    <button id="btnPesquisar" type="button">Pesquisar</button>
</div>

I tried to search for something in .js and jquery, but I can not execute the scripts because I do not have the "context" of the other page

The script I thought would look something like this:

<script>
     var url = www.paginaxyz.com.br;
     $(document, url).ready(function(){
         $("#Codigo").val($("#CodigoConsulta").val());
     });
</script>

Is it possible to do this?

Edit: * The landing page is from another company, as if I were to do an NFe query by access key, for example *

    
asked by anonymous 06.09.2018 / 15:40

1 answer

1

You can pass the parameter to query string , and read on the other page, something very common and simple:

<a href="www.paginaxyz.com.br?codigoConsulta=12345">Consultar</a>

NOTE: Here I am just putting the code directly in the link to illustrate, you can read the content dynamically by clicking the link to get the updated value.

Then, on page XYZ, read the contents of query string , which comes in the url. There are several ways to do this, here is an example copied from the OS: get query string paramenters

$.urlParam = function (name) {
    var results = new RegExp('[\?&]' + name + '=([^&#]*)')
                      .exec(window.location.search);
    return (results !== null) ? results[1] || 0 : false;
}

This code will create an extension in jquery , hence just use this function to retrieve the parameter:

$("#Codigo").val($.urlParam('codigoConsulta'));
    
06.09.2018 / 15:51