/    Sign up×
Community /Pin to ProfileBookmark

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.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangMay 09.2010 — You can only do that if both documents are on your domain
Copy linkTweet thisAlerts:
@Joshua2010authorMay 09.2010 — 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.
Copy linkTweet thisAlerts:
@FangMay 10.2010 — The document (html file) in the opened window.
Copy linkTweet thisAlerts:
@Joshua2010authorMay 10.2010 — 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>
×

Success!

Help @Joshua2010 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...