How to open new tab with data-href


Iggy's popularity

I'm making the table row clickable, but once clicked, I want to open a new tab. I tried to use data-targetbut it didn't work .

<tr class="table-row" data-href="mypage.php" data-target="_blank"></tr>

<script type="text/javascript">
    $(document).ready(function ($) {
        $(".table-row").click(function () {
            window.document.location = $(this).data("href");
        });
    });
</script>
minimally invasive

This can be done like this:

jQuery的:JSFiddle 1

$('.table-row').each(function() {
  var $th = $(this);
  $th.on('click', function() {
    window.open($th.attr('data-href'), $th.attr('data-target'));
  });
});

纯 JS :JSFiddle 2

var tableRows = document.getElementsByClassName('table-row');

for (var i = 0, ln = tableRows.length; i < ln; i++) {
  tableRows[i].addEventListener('click', function() {
    window.open(this.getAttribute('data-href'), this.getAttribute('data-target'));
  });
}

Related


How to open new tab with data-href

Iggy's popularity I'm making the table row clickable, but once clicked, I want to open a new tab. I tried to use data-targetbut it didn't work . <tr class="table-row" data-href="mypage.php" data-target="_blank"></tr> <script type="text/javascript"> $(docu

How to open new tab with data-href

Iggy's popularity I'm making the table row clickable, but once clicked, I want to open a new tab. I tried to use data-targetbut it didn't work . <tr class="table-row" data-href="mypage.php" data-target="_blank"></tr> <script type="text/javascript"> $(docu

Open the "href" variable in a new tab

Benjamin I am using selenium and chrome webdriver in python. I'm trying to store "href" in a variable ("link" in this case) and then open it in a new tab. I know how to open a dedicated website in a new tab using this way: driver.execute_script("window.open('h

Open the "href" variable in a new tab

Benjamin I am using selenium and chrome webdriver in python. I'm trying to store "href" in a variable ("link" in this case) and then open it in a new tab. I know how to open a dedicated website in a new tab using this way: driver.execute_script("window.open('h

How to open new tab with onclick="javascript:location.href"?

big brian I'm trying to find out if there is a way to use " javascript:location.href " to open a new tab . I can't use other methods to open the link because it needs to get the ID of a member of my site on load. I also can't make a javascript function because

How to open URL in new tab and transfer data

Brady Click First of all, I want to state that I am a beginner in coding. I've worked on a ticket WordPress site for editing from another programmer. Here is the current situation: Site A is my WordPress site. Site B is the website of the company that provides

VueJs use BootstrapVue to open HREF in new tab

Cesar I am using bootstrap to create a table and one of the fields is a link which should be opened in a new tab usingtarget="_blank" However, for some reason it doesn't work, why? thanks. Full code: <b-table striped hover :items="applications" :filter="fi

VueJs use BootstrapVue to open HREF in new tab

Cesar I am using bootstrap to create a table and one of the fields is a link which should be opened in a new tab usingtarget="_blank" However, for some reason it doesn't work, why? thanks. Full code: <b-table striped hover :items="applications" :filter="fi

"Open in new tab" click link does not open href value

99 encoder I am using Vue2 and I have and <a>markup . This works as expected with a left click (it's calling a method), but if I do a , which is the open value in this case, it 's wrong.href='#'@click.prevent="someMethod()" right click -> open in new tabhref W

How to open data tag url in new tab using Html

Gogobella64 Gfdrdrd I have this html code <div class="store-badge" data-name="Cheerswipe" data-google-play-url="https://play.google.com/store/apps/details?id=fr.puyou.cheerswipe" data-app-store-url="https://apps.apple.com/us/app/cheerswipe/id1468158095

How to open new tab in CasperJS

Salt I've been using the CasperJS testing framework to make some test suites since almost a month, but I'm facing an issue with one of them. Here's what I'm trying to do: I'm browsing a url (page 1) and have to do another from another url (simulating a new tab

How to open new tab in CasperJS

Salt I've been using the CasperJS testing framework to make some test suites since almost a month, but I'm facing an issue with one of them. Here's what I'm trying to do: I'm browsing a url (page 1) and have to do another from another url (simulating a new tab

How to open a file in a new tab?

jligeza : How can I use Ctrl+ to open a new file P, so it doesn't overwrite the current file, but uses a new tab? Also, if the file is already open on the tab, is it possible to centrally search for the file instead of opening it to avoid duplication? Keshan N

How to open new tab in CasperJS

Salt I've been using the CasperJS testing framework to make some test suites since almost a month, but I'm facing an issue with one of them. Here's what I'm trying to do: I'm browsing a url (page 1) and have to do another action from another url (simulating a

How to open a file in a new tab?

jligeza : How can I use Ctrl+ to open a new file P, so it doesn't overwrite the current file, but uses a new tab? Also, if the file is already open on the tab, is it possible to centrally search for the file instead of opening it to avoid duplication? Keshan N

How to open new tab in CasperJS

Salt I've been using the CasperJS testing framework to make some test suites since almost a month, but I'm facing an issue with one of them. Here's what I'm trying to do: I'm browsing a url (page 1) and have to do another action from another url (simulating a

Open a new "Angle" tab with object data?

plum I'm using Angular 7 and I want to open a new Angular tab with object data. When the user clicks the button, the object data is sent and a new tab is opened with that data. I have tried three things. I used 'window.open()'. I can easily open a new tab but

Open a new "Angle" tab with object data?

plum I'm using Angular 7 and I want to open a new Angular tab with object data. When the user clicks the button, the object data is sent and a new tab is opened with that data. I have tried three things. I used 'window.open()'. I can easily open a new tab but

How to redirect servlet to new tab and open Excel in new tab

tom I am trying to generate an Excel file from my servlet. Now, in my servlet, I have a click link which saves the excel sheet in a local folder. Now I want to open that excel sheet in a new tab. My servlet looks like this, In doPost, I am calling a method tha

How to redirect servlet to new tab and open Excel in new tab

tom I am trying to generate an Excel file from my servlet. Now, in my servlet, I have a click link which saves the excel sheet in a local folder. Now I want to open that excel sheet in a new tab. My servlet looks like this, In doPost I am calling a method that

Chrome extension: how to open links in new tab?

Tuyen Pham: In my Stackoverflow folder, there are stackoverflow.ico2 bellow files. When importing it into Chrome, it shows the icon in the address bar, but when I click it, Chrome doesn't open any new tabs. What am I doing wrong? manifest.json { "name": "Sta

How to open links in new tab in HTML?

Zenthyx programming I'm working on an HTML project, but I don't know how to open a link in a new tab without JavaScript. I already know that links can be opened in <a href="http://www.WEBSITE_NAME.com"></a>the same tab . Any ideas how to make it open in the ne

How to open new tab with Selenium WebDriver?

Bhakti Shah How to open new tabs in existing Firefox browser using Selenium WebDriver (aka Selenium 2)? long gar ten champani The following code will open the link in a new tab. String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN); driver.find

How to open newly created image in new tab?

John Stephen The code below creates the image at the bottom of the same page. How can I display the image in a new tab/window instead of the same page? success: function (data) { var image = new Image(); image.src = "data:image/jpg;base

How to open PDF files in a new tab

username I'm using JSF and I want to open a PDF file in a new tab when a button is clicked. XHTML <p:commandButton onclick="this.form.target = '_blank'" actionListener="#{managedBean.openFile(file)}" ajax="false" /> managed b

How to open URL in new tab via javascript

imaginary I'm working on a chatbot using peekabot (links to documentation and official samples are provided below) and would like to be able to open a URL in a new tab when the user clicks on some new tab (as you have the option to use plain html). options. Re

How to open pdf in new tab in reactjs?

Gorak Nath We save the pdf document in the database, it is returned as byte array from the webapi, now from the UI, I have to open the pdf in a new tab in the browser and the user should be able to download the pdf. How to meet the requirements for opening and