Auto Input Fill in another browser tab via script

Asked

Viewed 261 times

4

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

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

My website:

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

Page XYZ:

<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’t run the scripts because I don’t 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>

It is possible to carry out this process ?

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

  • wants to do in client?

  • Why don’t you make a post to the other page ?

  • You have already tried to pass as the GET parameter of the XYZ page?

  • In my case, the landing page is not mine, and I don’t know the route/name of the parameter that it expects for the query ... I tried to pass via get, but it didn’t work ..

  • Inspect the page, see which method its form uses. Do the same in your system.

1 answer

1


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

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

OBS.: here I’m just putting the code right on the link to exemplify, you can read the content dynamically by clicking on the link to get the updated value.

Then, on the XYZ page, read the contents of query string, that comes in the url.
There are several ways to do this, here’s 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 create an extension on jquery, then just use this Function to retrieve the parameter:

$("#Codigo").val($.urlParam('codigoConsulta'));

Browser other questions tagged

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