473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

open webpage 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:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function open_win() {
  5. window.open("http://yahoo.com", "newwindow1")
  6. window.open("http://google.com", "newwindow2")
  7. }
  8. </script>
  9. </head>
  10. <body>
  11. <form>
  12. <input type=button value="Open Windows" onclick="open_win()">
  13. </form>
  14. </body>
  15.  
  16. </html>


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


Expand|Select|Wrap|Line Numbers
  1. <script language="javascript>
  2. function fakeTab() {
  3.   if (window.event.keyCode == 13 && window.event.srcElement.tagName == "INPUT")
  4.      window.event.keyCode = 9;
  5. }
  6. documet.onkeydown = fakeTab;
  7. </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.
May 9 '10 #1
4 7509
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:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function open_win() {
  5. window.open("http://yahoo.com", "newwindow1")
  6. window.open("http://google.com", "newwindow2")
  7. }
  8. </script>
  9. </head>
  10. <body>
  11. <form>
  12. <input type=button value="Open Windows" onclick="open_win()">
  13. </form>
  14. </body>
  15.  
  16. </html>


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


Expand|Select|Wrap|Line Numbers
  1. <script language="javascript>
  2. function fakeTab() {
  3. if (window.event.keyCode == 13 && window.event.srcElement.tagName == "INPUT")
  4. window.event.keyCode = 9;
  5. }
  6. documet.onkeydown = fakeTab;
  7. </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.
May 9 '10 #2
gits
5,390 Expert Mod 4TB
for your specific task you don't need to fire a keypress event ... which wouldn't even work ... you would just need to use the focus() method ... here is an example ...

kind regards
May 9 '10 #3
Thanks. Tell me if I am doing this write. Let's say I want to focus on the text area of two separate websites (e.g. google.com, yahoo.com). I would open the windows by using this first:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function open_win() {
  5. window.open("http://google.com", "newwindow1")
  6. window.open("http://yahoo.com", "newwindow2")
  7. }
  8. </script>
  9. </head>
  10. <body>
  11. <form>
  12. <input type=button value="Open Windows" onclick="open_win()">
  13. </form>
  14. </body>
  15.  
  16. </html>
  17.  
and then to focus on the text area for both of those window I would us this:


Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <script language="JavaScript">
  4.     function function1() {
  5.         document.all.myElement.focus();
  6.     }
  7.     function function2() {
  8.         alert("onFocus event has been fired");
  9.     }
  10. </script>
  11. <input id="myElement" type="text" value="" onfocus="function2();">
  12. <input type="button" 
  13.        value="Give focus to the text input element and fire the event" 
  14.        onclick="function1();">
  15. </body>
  16. </html>
  17.  
But, how do I make sure it knows that I want it focus on the text areas of the two windows I opened?
May 10 '10 #4
gits
5,390 Expert Mod 4TB
??? huh? ... you could only focus one element at a time, it should set the focus onload of the window ... ahh ... and when you include a page from another domain to that window ... as you do ... you cannot script it ... it's for security reasons ... and your script will throw an error since that would be considered a XSS (cross site scripting) attack ...

kind regards
May 11 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Serdge Kooleman | last post by:
How to get "Key press" event when i'm working with DataGrid (winforms). Seems to me that standard events "KeyUp, KeyPress" are ignored :-( Thank you
4
by: Rich | last post by:
Hi, I would like to setup some events tied to the function keys but I'm not sure where to start; any help would be greatly appreciated.
1
by: james henderson | last post by:
Hi, I want to create an application that can record and reproduce all user interaction with a GUI. For this I need to be able to simulate mouseclick events. Can anyone tell me how I can do this.
1
by: Patrick | last post by:
Hi All, I would like to track the users of a database I have. To do this, I have a function which finds their net id, and i would like to run this function when they open the db, and then write...
0
by: gmguyx | last post by:
I tried using urllib.urlopen to open a personalized webpage (my.yahoo.com) but it doesn't work: print urllib.urlopen(http://my.yahoo.com).read() Instead of returning my.yahoo.com, it returns a...
0
by: gmguyx | last post by:
I tried using urllib.urlopen to open a personalized webpage (my.yahoo.com) but it doesn't work: print urllib.urlopen(http://my.yahoo.com).read() Instead of returning my.yahoo.com, it returns a...
3
by: win | last post by:
How to get the keycode press in a web form Vincent
6
by: Charles Law | last post by:
I have a base class and derived classes that relate to a set of documents I process. e.g. DocBase, DocA, DocB, DocC. The processing of each document is handled in teh derived classes, as you might...
6
by: Studlyami | last post by:
Hey all, I'm trying to create a simple (I think it should be simple) batch file. I want this file to open Internet Explorer 6 go to the webpage SIRIUS Satellite Radio - The Best Radio On Radio and...
0
by: cyhcyhhychyc | last post by:
topology: 8 client computers------->switch-------->modem------->telephone line total bandwidth:2Mbit upstream bandwidth:512kbit when one is uploading files(for axample .rar of 1MB),the others...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.