1

What's the proper way to extract wiki page number from page source, with jquery?

For example, for wiki page W4567 i'd like to get the number "4567" so I can do further things with it.

Btw, I see all around code like: onload="g1(this, 'WikiPage', 2508, 2, false)". I wonder if that's the right thing to use.

flag

2 Answers

1

I would use the window.location object to get the URL and then look for the W4567 in it.

You could also write a plugin to add a javascript object to the page with whatever article info you need.

link|flag
1

If you'd also like your code to work on pages where the wiki number is specified via the ixWikiPage parameter (e.g. when you are editing that wiki page), you could say this:

var rgWikiResults = /(?:\?W|ixWikiPage=)(\d+)/.exec(window.location.search);
var ixWiki = rgWikiResults ? rgWikiResults[1] : null;
link|flag
snazzy! how about when the page is viewed? (e.g. /default.asp?W123 or /?W123) – adambox May 18 2010 at 16:08
@adambox: Those should all work; the regular expression searches for ?W OR ixWikiPage= followed by a number. The two examples you've provided are the ?W followed by a number case. – Daniel LeCheminant May 18 2010 at 16:50
Sorry, I didn't understand what are you guys talking about. – Pavel Radzivilovsky May 23 2010 at 11:04
@Pavel: We're discussing ways to reliably get the wiki page number, given the URL of the page that you're on (be it a Wiki view page, or a Wiki edit page) – Daniel LeCheminant May 23 2010 at 11:38

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.