Arefe
Arefe

Reputation: 12461

How to open new HTML tab after clicking on the button

I have the landing page with some buttons to function.

enter image description here

When I click the Send Money button, it opens the sendMoney.html in the same tab. The code is following,

$("#sendMoney").click(function () {
    var address = $('#address').find(":selected").text();
    location.href = 'sendMoney.html#' + address;

});

How to open the sendMoney.html in the new tab?

Upvotes: 1

Views: 595

Answers (4)

Milan Chheda
Milan Chheda

Reputation: 8249

You need to use window.open() which will open new tab in most of the new browsers. Here is the updated code:

$("#sendMoney").click(function () {
    var address = $('#address option:selected').text();
    window.open('sendMoney.html#' + address);
});

Upvotes: 0

Saurabh
Saurabh

Reputation: 1631

You can use <a> button text here <a/> to make a button and use attribute target as _blank to open page in new tab

Or

you can use window.open() function as

window.open(URL, name,)

Value for name can be

  • blank - URL is loaded into a new window. This is default

  • _parent - URL is loaded into the parent frame

  • _self - URL replaces the current page

  • _top - URL replaces any framesets that may be loaded name - The name of the window (Note: the name does not specify the title of the new
    window)

Upvotes: 0

sumit chauhan
sumit chauhan

Reputation: 1300

$("#sendMoney").click(function () {
    var address = $('#address').find(":selected").text();
    window.open('sendMoney.html#' + address);
});

Instead of using window.location, use window.open("your link");. With window.location its not possible to do that.

Upvotes: 2

Rory McCrossan
Rory McCrossan

Reputation: 337714

To do what you require you can use window.open(). Although the name suggest it'll open a popup window, the request will actually be redirected to a new tab in all modern browsers. Try this:

$("#sendMoney").click(function () {
    var address = $('#address').find(":selected").text();
    window.open('sendMoney.html#' + address);
});

Upvotes: 3

Related Questions