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.

Making Javascripts run on specific pages.

View previous topic View next topic Go down

Making Javascripts run on specific pages.

Post by Arrandale on April 17th 2012, 5:46 am

I'll preface this question by saying that I am really bad at javascript, I very recently started trying to learn some basic stuff, so no judgment please.

As the title suggests I'm trying to a add a really basic script that will run on a specific thread of the forum. To do it, I went to javascript management and a created a script that would run on all pages. Then I put this as the content:

var window = window.location;

if (window === "http://www.superiorrp.org/t289-receive-vip") {
alert("test message")
}

Anyway, it completely failed, does anyone know how to fix this so it works, or know another method of making a script run only on a specific page of the forum. Thanks.

Arrandale
New Member

Posts : 4
Reputation : 1
Language : English

Back to top Go down

Re: Making Javascripts run on specific pages.

Post by LGforum on April 17th 2012, 3:09 pm

This would work for any topic :
Code:

(function(){
var r = /\/t(\d+)-.*/;
if(r.test(window.location.pathname)) {
  var topic_id = r.replace(r,'$1');
  if(topic_id == 289) {
    alert('testing');
  }
  else if(topic_id == 1) {

  }
}
})();

Just keep adding else-ifs for more topics using the topic ids.

LGforum
Hyperactive

Male Posts : 2260
Reputation : 258
Language : English
Location : UK

http://www.avacweb.com/

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