The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Acces onClick link

2 posters

Go down

Acces onClick link Empty Acces onClick link

Post by Light Elf Mon May 21 2012, 21:10

How can I access with javascript to link. For example there is category, and inside it there are forums. When someone click on forum I want to trigger javascript. How?
Light Elf
Light Elf
Forumember

Posts : 144
Reputation : 11
Language : English

Back to top Go down

Acces onClick link Empty Re: Acces onClick link

Post by LGforum Mon May 21 2012, 21:40

Set an event listener.
element.setEventListener() or element.attachEvent.

Though you can use jQuery's events API, and just do $(selector).click(function(e) { });
Which does the same stuff, but sorts out all the browser support for you.
LGforum
LGforum
Hyperactive

Male Posts : 2265
Reputation : 264
Language : English
Location : UK

Back to top Go down

Acces onClick link Empty Re: Acces onClick link

Post by Light Elf Mon May 21 2012, 21:47

Can you give me one example how to use this? I am unknown with this part of javascript, and mostly with jQuery.
Light Elf
Light Elf
Forumember

Posts : 144
Reputation : 11
Language : English

Back to top Go down

Acces onClick link Empty Re: Acces onClick link

Post by LGforum Tue May 22 2012, 00:12

I actually wrote a script on FMQuery for this exact purpose a while ago, here it is:
Code:

var copyright_notice = 'Redirection Forums script for Forumotion Boards. Copyright © by LGforum. All Rights Reserved. Use and  modification of this script is not allowed without this entire copyright notice in the original, copied, or modified script. No distribution without consent.';
var redirectForums = {
        f43: 'http://avacweb.com/',
        f46: 'http://malware-site.www/'     
};
(function(){
var fid = window.location.pathname.replace(/.*\/(f\d+)-.*/,'$1');
if(fid in redirectForums) window.location = redirectForums[fid];
})();

$(function(){
        var rows = $('.forums dl.icon').get();
        for(var i=0,l=rows.length;i<l;i++) {
                var flink = rows[i].getElementsByTagName('h3')[0] || rows[i].getElementsByTagName('h2')[0];
                if(!flink) continue;
                flink = flink.firstChild;
                var fid = flink.href.replace(/.*\/(f\d+)-.*/,'$1');
                if(fid in redirectForums) {
                        var new_link = redirectForums[fid];
                        flink.href = new_link;
                        flink.setAttribute('target','_blank');
                        while( rows[i].lastChild.className != 'dterm') { rows[i].removeChild(rows[i].lastChild)}
                }
        }
});
It should be pretty straight forward how to use. You add the forum ID, followed by a semi-colon, followed by the link you wish it to redirect to.
For example this bit: f43: 'http://avacweb.com/'
Means clicking on the link to forum 43 (check their unique ID in their URL) will redirect to avacweb.com
LGforum
LGforum
Hyperactive

Male Posts : 2265
Reputation : 264
Language : English
Location : UK

Back to top Go down

Acces onClick link Empty Re: Acces onClick link

Post by Light Elf Tue May 22 2012, 11:43

My idea was to triger a prompt box when someone click on forum in category. And when he enter good password he will be redirected into, else he will stay where he is. Very Happy
Light Elf
Light Elf
Forumember

Posts : 144
Reputation : 11
Language : English

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum