Add event code on click in LabelField

My application has a LabelField with the text "www.google.com". When a user clicks, the default browser should open at www.google.com.

+3
source share
2 answers

try this code

final LabelField label = new LabelField("http://www.google.com",LabelField.FOCUSABLE){
            public boolean navigationClick (int status , int time){
                 BrowserSession bSession = Browser.getDefaultSession();
                 bSession.displayPage(label.getText());
                 return true;
            }
        };
+3
source

you can use jquery. try this code:

<html>
<head>
<title>Opens a link</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.js"></script>
</head>
<body>
<label for="link" id="target">www.google.com</label>
<script type="text/javascript">
    $('#target').click(function () {
        var url = $(this).text();
        window.location = "http\://"+url;
    });
</script>
</body>
</html>
-3
source

All Articles