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.

Making Javascripts run on specific pages.

2 posters

Go down

Making Javascripts run on specific pages. Empty Making Javascripts run on specific pages.

Post by Arrandale 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.
avatar
Arrandale
New Member

Posts : 4
Reputation : 1
Language : English

Back to top Go down

Making Javascripts run on specific pages. Empty Re: Making Javascripts run on specific pages.

Post by LGforum 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
LGforum
Hyperactive

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

Back to top Go down

Back to top

- Similar topics

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