Javascript to simulate Keyboard

Asked

Viewed 503 times

0

Hello, I have the following case, an external page opens inside my iframe, I need javascript to simulate the "TAB" key until I reach the login field. so much so why my problem is in finding a way to make you simulate that "TAB" without any other event has been triggered, just loading the page.

follows example, but not

<?php

echo '<script type="text/javascript" src="js/jquery.js"> </script>';

?>

<html>


<iframe src="http://alelo.com.br/consulta-saldo-extrato-alelo.html" style="width:100%; height:100%">

<script>

alert('.-.');

</script>

</html>
  • Explain further what you want, the question is not clear.

  • summary a key, when pag load want q be simulated "tab" until you reach the card numer field.

  • I marked as duplicate of your other question. As I had answered there this domain does not allow CORS, and it will not be possible to access document of that page.

  • Keyboard has nothing to do with Cors but check how you want, if you do not know how to leave it there until someone who knows how to answer vlw!

  • Just simulate a tab... this can’t be that hard

  • 1

    @Raphaelaraujo to manipulate a tab you have to touch the events of the iframe to fire keypress, then you must have access to document and CORS is not linked on that site. It is not bad will, some sites turn off CORS to prevent a program try for example to login and test passwords until right.

Show 1 more comment

1 answer

0

Maybe that’s what you want, just using the "autofocus" attribute in "input".

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>focus demo</title>
<style>
    span {
        display: none;
    }
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

<p><input autofocus type="text"> <span>Login</span></p>
<p><input type="password"> <span>Senha</span></p>

<script>
    $( "input" ).focus(function() {
        $( this ).next( "span" ).css( "display", "inline" ).fadeOut( 1000 );
    });
</script>

Automatically when loading the page the focus is given to the first input of the page.

  • Thanks for the answer, but in my case the inputs I want are not from my page, are from another page that is on the web, so I can not put the autofocus attribute because the input is not mine.

Browser other questions tagged

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