0

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?

Pshemo
  • 122,468
  • 25
  • 185
  • 269
Aksparks04
  • 41
  • 1
  • 2

2 Answers2

1

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

Community
  • 1
  • 1
Mario Corchero
  • 5,257
  • 5
  • 33
  • 59
  • In other words, either wrap the code inside a function or put a `window.open()` followed by `location=`/`location.href='http://newurl'` inline with the HTML, but I'd suggest a function or listener. – Fabrício Matté Jun 30 '12 at 23:50
0

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>
Prashanth Thurairatnam
  • 4,353
  • 2
  • 14
  • 17