dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: Open new window and simulate key press events

Hybrid View

  1. #1
    Join Date
    May 2010
    Posts
    3

    Post Open new window and simulate key press events

    I have been trying to merge two command scripts, and have gotten nothing. I am trying to use javascript commands to open a new window on Firefox, and on that opened window simulate a Tab key press.

    This is the full script that I have come up with so far to open two windows, with the websites being yahoo.com and google.com. ***To fully help me please copy this script, paste to Notepad, save as a .html file and run it on Firefox. You will notice a "Open Windows" button will appear. When you click on it the windows will open:

    <html>
    <head>
    <script type="text/javascript">
    function open_win() {
    window.open("http://yahoo.com", "newwindow1")
    window.open("http://google.com", "newwindow2")
    }
    </script>
    </head>
    <body>
    <form>
    <input type=button value="Open Windows" onclick="open_win()">
    </form>
    </body>

    </html>



    Now this is what I have come up to simulate a Tab key event when you press the ENTER key:


    <script language="javascript>
    function fakeTab() {
    if (window.event.keyCode == 13 && window.event.srcElement.tagName == "INPUT")
    window.event.keyCode = 9;
    }
    documet.onkeydown = fakeTab;
    </script>


    What I want to do is merge these two scripts, so that when I press that "Open Windows" button, the new window opens and the Tab key press is immediately simulated to move to the next field on the webpage.

    I understand that JavaScript is event driven, meaning some event has to occur before you can make things happen. The user must push a key or click somewhere on the page before you can relaly do anything with an event. I want to have the clicking of the "Open Windows" button, that first triggering event which opens a window and simulates the tab key press on that window.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    You can only do that if both documents are on your domain

  3. #3
    Join Date
    May 2010
    Posts
    3
    What do you mean by document? I just want an even to happen on an opened window if that window is opened. Please be more clear.

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    The document (html file) in the opened window.

  5. #5
    Join Date
    May 2010
    Posts
    3
    If you copy the first script I wrote, and then paste it into a Notepad file, then save it as an .html file, and then open that file in Internet Explorer or Firefox you will see what I mean. When you run it, you will see a new window that has an "Open Windows" button. When you press the button, the new windows appear.

    For instance I can open 10 windows, if I were to run this command:

    <html>
    <head>
    <script type="text/javascript">
    function open_win() {
    window.open("http://yahoo.com", "newwindow1")
    window.open("http://yahoo.com", "newwindow2")
    window.open("http://yahoo.com", "newwindow3")
    window.open("http://yahoo.com", "newwindow4")
    window.open("http://yahoo.com", "newwindow5")
    window.open("http://yahoo.com", "newwindow6")
    window.open("http://yahoo.com", "newwindow7")
    window.open("http://yahoo.com", "newwindow8")
    window.open("http://yahoo.com", "newwindow9")
    window.open("http://yahoo.com", "newwindow10")
    }
    </script>
    </head>
    <body>
    <form>
    <input type=button value="Open Windows" onclick="open_win()">
    </form>
    </body>

    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles