HTML button opening link in new tab

前端 未结 8 1248
挽巷
挽巷 2020-12-05 17:32

So this is the simple code for the button to open a certain link

                
相关标签:
8条回答
  • 2020-12-05 17:42

    You can also add this to your form:

    <form ... target="_blank">
    
    0 讨论(0)
  • 2020-12-05 17:42

    Try using below code:

    <button title="button title" class="action primary tocart" onclick=" window.open('http://www.google.com', '_blank'); return false;">Google</button>
    

    Here, the window.open with _blank as second argument of window.open function will open the link in new tab.

    And by the use of return false we can remove/cancel the default behavior of the button like submit.

    For more detail and live example, click here

    0 讨论(0)
  • 2020-12-05 17:44

    Try this

    window.open(urlValue, "_system", "location=yes");
    
    0 讨论(0)
  • 2020-12-05 17:44

    If you're in pug:

    html
        head
            title Pug
        body
            a(href="http://www.example.com" target="_blank") Example
            button(onclick="window.open('http://www.example.com')") Example
    

    And if you're puggin' Semantic UI:

    html
        head
            title Pug
            link(rel='stylesheet' href='https://cdn.jsdelivr.net/npm/semantic-ui@2.3.3/dist/semantic.min.css')
        body
            .ui.center.aligned.container
                a(href="http://www.example.com" target="_blank") Example
            .ui.center.aligned.container
               .ui.large.grey.button(onclick="window.open('http://www.example.com')") Example
    
    0 讨论(0)
  • 2020-12-05 17:47

    With Bootstrap you can use an anchor like a button.

    <a class="btn btn-success" href="https://www.google.com" target="_blank">Google</a>
    

    And use target="_blank" to open the link in a new tab.

    0 讨论(0)
  • 2020-12-05 17:48

    Use '_blank'. It will not only open the link in a new tab but the state of the original webpage will also remain unaffected.

    0 讨论(0)
提交回复
热议问题