0

please see this thread first :
How Simulate “Enter Key Hit” Using With Both Javascript & Jquery
and check out this comment in that thread :

@RobG :
you can dispatch a keypress event with appropriate parameters from a particular target element, however browsers may not treat it exactly like user input. You can't fool them, they know where the event came from. See also Creating and triggering events.

@RobG was right.
browsers can recognize our simulation by these codes:

var e = jQuery.Event("keypress");
e.which = 13; //choose the one you want
e.keyCode = 13;
$("#theInputToTest").trigger(e);

is there a way to simulate that just like a HUMAN DO?

Community
  • 1
  • 1
SilverLight
  • 19,668
  • 65
  • 192
  • 300

2 Answers2

0

Not from straight javascript. If you really want to simulate it, look into using WebDriver to simulate real user interaction.

This is not something you're going to be able to do in a normal web page's lifecycle though, it's generally used for other purposes such as integration testing.

dherman
  • 2,832
  • 20
  • 23
0

You can't fool them, they know where the event came from.

Rob had already explain that its not possible may be for the security reasons.

Somnath Kharat
  • 3,570
  • 2
  • 27
  • 51