Making Javascripts run on specific pages.

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 === "") {
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.

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 :

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


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

Male Posts : 2263
Reputation : 260
Language : English
Location : UK

Back to top Go down

Back to top

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