简体   繁体   中英

How to open in new tab using button

<script type="text/html" id="marketSelection">
        <h3 class="choose-store">Choose your store:</h3>
        <div class="text-center">
            <% _.each(suppliers, function (supplier) { %>
            <button class="btn-custom supermarket-item" data-id="<%= supplier.id %>">
                <i></i><%= supplier.name %>
            </button>
            <% }) %>
        </div>

        /*File:src/js/data.js*/
        var cookie_selectedSupermarket = CookieManager.retrieve('supplierId'),
            cookie_selectedPostalCode = CookieManager.retrieve('deliveryareaCode'),
            cookie_q = CookieManager.retrieve('q');
        Data = {
            availabilityList: [JSON_STORE_AVAILABILITY_LIST],
            postalCodes: [JSON_POSTAL_CODES],

            hardCode: {
                selected_supermarket: null,
                selected_postal_code: null,
                q: null
            },
            query: {
                selected_supermarket: Utils.getQueryParameterByName('selected_supermarket'),
                selected_postal_code: Utils.getQueryParameterByName('selected_postal_code'),
                q: Utils.getQueryParameterByName('q')
            },
            cookie: {
                selected_supermarket: cookie_selectedSupermarket ? cookie_selectedSupermarket.value : null,
                selected_postal_code: cookie_selectedPostalCode ? cookie_selectedPostalCode.value : null,
                q: cookie_q ? cookie_q.value : null
            },

            PROTOCOL: 'https://',
            DOMAIN: 'www.test.com.au',
            PATH: '/',
            redirectURI: '/all-products/?supplier=<%= supplierId %><% if (q) { %>&q=<%= q %><% } %>'
        };

I have an issue having the buttons open in new tab. In HTML - I know we have to add in _blank but for cases like this, what is the solution?

Thanks

EDIT: Added in more codes so that it's more clear what I want.

You can use Javascript

function openTab(url) {
  var win = window.open(url, '_blank');
  win.focus();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM