Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polymer core-button link

Tags:

polymer

This seems like a really stupid question, but how do I make a button link to a webpage?

I've tried the following

<paper-button raisedButton class="colored" iconSrc="http://g.twimg.com/Twitter_logo_white.png"><a href="http://twitter.com/username" target="_blank">follow</a></paper-button>


<paper-button raisedButton class="colored" iconSrc="http://g.twimg.com/Twitter_logo_white.png" link="http://twitter.com/username">follow</paper-button>
like image 812
jxn Avatar asked Jul 08 '14 05:07

jxn


4 Answers

This might be over-the-top, but quite Polymer-ey. You could use:

<paper-button 
    raisedButton 
    class="colored" 
    iconSrc="http://g.twimg.com/Twitter_logo_white.png" 
    label="Follow"
    link="http://twitter.com/username"
    on-tap="{{goLink}}"></paper-button>

Then in your script have:

Polymer('element-name', {
    goLink: function(e) {
        window.location.href = e.target.getAttribute('link');
    }
});

Then all your buttons can just use the same link="WHATEVER" on-tap="{{goLink}}" attributes.

like image 86
Cram42 Avatar answered Jan 20 '23 20:01

Cram42


In Polymer version I am using (1.2), you can simply do this:

<a href="http://google.com"><paper-button raised>Account</paper-button></a>

I think this simplicity has been available as of Polymer 1.0.

like image 36
The Onin Avatar answered Jan 20 '23 20:01

The Onin


What about onclick?

<paper-button raisedButton label="test" onclick="javascript:alert('f')"></paper-button>
like image 41
Michael Sync Avatar answered Jan 20 '23 22:01

Michael Sync


I solved it by doing the following:

<paper-button raisedButton class="colored" iconSrc="iconurl" onclick="window.open('url','_blank');">label text</paper-button>
like image 44
jxn Avatar answered Jan 20 '23 20:01

jxn