Adding href attribute to bootstrap button

EndingLegacy

I'm trying to make it so that my button will open a url in a new tab.

I can get it to work using window.location.href, but the url doesn't open in a new tab that way.

I'm using jQuery and Javascript, and the code itself is inside of a larger jQuery function.

$('#code').click(function(){
    window.location.href = 'http://www.example.com'
});

The button has no href attribute on page load.

<button id="code" type="submit" class="btn btn-success" style="width:400px;"><span class="glyphicon glyphicon-download"></span> Generate Code</button>

I've tried using .attr and .prop though it hasn't worked either. I'm kinda new to this stuff so I could've just done something wrong.

I'm open to either adding an href to the button or using the .click function or whatever, I just need to get this to open to a new tab.

Edit:: Ok, more explanation.

On Page load, the button onclick starts a timer that increments a progressbar. After the progressbar is done I want the button to open a link.

XiozZe

This will open the url in a new window:

$('#code').click(function(){
window.open("http://www.w3schools.com");
});

http://www.w3schools.com/jsref/met_win_open.asp

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jquery adding variables to href attribute

From Dev

jQuery adding auto link to href attribute

From Dev

md-button disappears when adding an href

From Dev

Attribute href not allowed on element button at this point

From Dev

Attribute href not allowed on element button at this point

From Dev

Adding a bootstrap glyphicon to a button in rails

From Dev

bootstrap button onclick and location.href

From Dev

Button's style is adding unknown attribute - Android

From Dev

Adding bootstrap attribute to custom MenuRenderer in JSF

From Dev

Correct way of adding a button to a navbar in Bootstrap 3

From Dev

Angular UI Bootstrap Popover adding a close button

From Dev

react bootstrap - adding custom bsStyle property to button

From Dev

Get the Attribute ID of Button in Bootstrap & AngularJS

From Dev

Get the Attribute ID of Button in Bootstrap & AngularJS

From Dev

Add "disabled" attribute to Bootstrap button via AJAX

From Dev

Adding button next to input, horizontal form style - Bootstrap

From Dev

Adding a button that looks like a link in Bootstrap3's navbar

From Dev

Circle button becomes ellipsis after adding border with Bootstrap

From Dev

Editing bootstrap editable dialogue box(Adding X close button on the top)

From Dev

Flask-Bootstrap, flask-wtf, adding class to submit button

From Dev

set bootstrap "required" attribute on textarea only if specific radio button selected

From Dev

Adding url into <a href=""> with Emmet

From Dev

Adding a #href anchor to a webpage

From Dev

Adding url into <a href=""> with Emmet

From Dev

Adding javascript ID as Href

From Dev

Binding to the href attribute in a link

From Dev

Filter XSS in href attribute?

From Dev

Alternate link in href attribute

From Dev

xpath - Get href attribute

Related Related

  1. 1

    jquery adding variables to href attribute

  2. 2

    jQuery adding auto link to href attribute

  3. 3

    md-button disappears when adding an href

  4. 4

    Attribute href not allowed on element button at this point

  5. 5

    Attribute href not allowed on element button at this point

  6. 6

    Adding a bootstrap glyphicon to a button in rails

  7. 7

    bootstrap button onclick and location.href

  8. 8

    Button's style is adding unknown attribute - Android

  9. 9

    Adding bootstrap attribute to custom MenuRenderer in JSF

  10. 10

    Correct way of adding a button to a navbar in Bootstrap 3

  11. 11

    Angular UI Bootstrap Popover adding a close button

  12. 12

    react bootstrap - adding custom bsStyle property to button

  13. 13

    Get the Attribute ID of Button in Bootstrap & AngularJS

  14. 14

    Get the Attribute ID of Button in Bootstrap & AngularJS

  15. 15

    Add "disabled" attribute to Bootstrap button via AJAX

  16. 16

    Adding button next to input, horizontal form style - Bootstrap

  17. 17

    Adding a button that looks like a link in Bootstrap3's navbar

  18. 18

    Circle button becomes ellipsis after adding border with Bootstrap

  19. 19

    Editing bootstrap editable dialogue box(Adding X close button on the top)

  20. 20

    Flask-Bootstrap, flask-wtf, adding class to submit button

  21. 21

    set bootstrap "required" attribute on textarea only if specific radio button selected

  22. 22

    Adding url into <a href=""> with Emmet

  23. 23

    Adding a #href anchor to a webpage

  24. 24

    Adding url into <a href=""> with Emmet

  25. 25

    Adding javascript ID as Href

  26. 26

    Binding to the href attribute in a link

  27. 27

    Filter XSS in href attribute?

  28. 28

    Alternate link in href attribute

  29. 29

    xpath - Get href attribute

HotTag

Archive