Aksparks04
Aksparks04

Reputation: 51

Generate 2 events with one click

I'm working on a website. I have a page with a button on it. When the user clicks the button, I'd like the following 2 things to happen:

(1). Current page (with the button) redirects to a new page

(2). A linked external webpage (say google) is opened in a new window

Any ideas on how to achieve this?

Upvotes: 0

Views: 113

Answers (2)

Prashanth Thurairatnam
Prashanth Thurairatnam

Reputation: 4361

Here is a sample HTML page that will open yahoo in current window (you can replace with your own page) and google in a new window. For tabbed browsers it would open a new tab instead of a new window. You can call it in any order.

<html>
<head>

<script type="text/javascript">
function openwindows()
{
window.open("http://www.yahoo.com", "_self")
window.open("http://www.google.com")
}
</script>

</head>
<body>
<input type="button" value="open" onclick="openwindows()"
</body>
</html>

Upvotes: 0

Mario Corchero
Mario Corchero

Reputation: 5575

Do 2 first and the 1.

I mean, open a new window first and the change the page and not in the reverse order.

To redirect check: How to redirect to another webpage in JavaScript/jQuery?

To open a new window: http://www.w3schools.com/jsref/met_win_open.asp

And by the way, you still have only one event, the mouse event, what you want is two actions to atached to the same event at the same block of code

Upvotes: 1

Related Questions