Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to simulate a KEY PRESS event


    Hi,

    Hi, I want to simulate user KEY PRESS (not mouse clicking) automatically on a screen every time that a pop up window (script error message) is opened on the screen OR detecting when an an iframe gets focus.

    My goal: Automatically closes the pop up window.

    If anybody know the exact code please post it.

    FG

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,241
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    Not possible - for security reasons.

    You can use setTimeout() to close a popup window after a pre-determined interval. But you cannot simulate a user key-press or mouse click

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 01-12-2012 at 09:42 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    It is would be very useful. I was thinking in setTimeout(), because what I need it to close the pop up window after an interval in seconds after it open

    FG

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,241
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    Code:
    <script type="text/javascript">
    var count = 0;
    var tim;
    function checktime() {
    count ++;
    if (count==6) {  // 6 seconds
    window.close();
    }
    tim = setTimeout(checktime,1000);
    }
    </script>
    Note that for security reasons the close method closes only windows opened by JavaScript using the open method. If you attempt to close any other window, a confirm message is displayed, asking the user to choose whether the window is to be closed or not.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •