PDA

View Full Version : Listen for an onclick attached to a hyperlink



8dot3
25 Aug 2011, 11:38 AM
I have a DataView that renders content with a template and I need to catch onclick events from hyperlinks in the template so I can open the link in Phonegap's ChildBrowser plugin.

I have this code in my template but I am not able to receive the onclick.


<a onclick="openChildBrowser('test')"><span class="url">{URL}</span></a>


Any thoughts on how this can be achieved?

jjerome
25 Aug 2011, 11:59 AM
use the itemSelector config for the DataView. if you are only selecting the hyperlinks, then you'd want to set the itemSelector: 'a' to fire the itemtap event when the user taps on the hyperlink in the tpl. Add a listener to the DataView:



listeners: {
itemtap: function(record, index, item){
//look to see what is stored in the 'item' parameter and 'record' parameter. See if your hyperlink url gets picked up there.
//after you get your url, you can open a new window with that url I think with this
window.open('url to open','window name','attribute1,attribute2');

//copied from http://www.pageresource.com/jscript/jwinopen.htm
//1.'url to open'
//This is the web address of the page you wish to appear in the new window.
//2. 'window name'
//You can name your window whatever you like, in case you need to make a reference to the window later.
//3. 'attribute1,attribute2'
//As with alot of other things, you have a choice of attributes you can adjust.
}

}


Give that a try.

8dot3
29 Aug 2011, 10:50 AM
This worked like a charm. Thank you.