The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Acces onClick link

View previous topic View next topic Go down

Acces onClick link

Post by Light Elf on May 21st 2012, 9:10 pm

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
Forumember

Posts : 144
Reputation : 11
Language : English

Back to top Go down

Re: Acces onClick link

Post by LGforum on May 21st 2012, 9:40 pm

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
Hyperactive

Male Posts : 2254
Reputation : 254
Language : English
Location : UK

http://www.avacweb.com/

Back to top Go down

Re: Acces onClick link

Post by Light Elf on May 21st 2012, 9:47 pm

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

Light Elf
Forumember

Posts : 144
Reputation : 11
Language : English

Back to top Go down

Re: Acces onClick link

Post by LGforum on May 22nd 2012, 12:12 am

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
Hyperactive

Male Posts : 2254
Reputation : 254
Language : English
Location : UK

http://www.avacweb.com/

Back to top Go down

Re: Acces onClick link

Post by Light Elf on May 22nd 2012, 11:43 am

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
Forumember

Posts : 144
Reputation : 11
Language : English

Back to top Go down

View previous topic View next topic Back to top


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