Is there any way to check if a specific page exists, using JavaScript, and run a function only if it does?
Topic on Project:Support desk/Flow
Appearance
Maybe you could perform a query on the database, searching for pages having titles similar to that page, or fetch the id from that page. Then you could implement a check, like:
result=query on the db where title like *page to look for*
if (result has rows)
{
it exists!run the function()
} else {
it doesnt exists!dont do nothing!
}
Use the API.
1 new mw.Api().get( {
2 action: "query",
3 titles: [ "This doesn't exist", "Main Page" ],
4 } ).then( function( ret ) {
5 $.each( ret.query.pages, function() {
6 if ( this.missing !== "" ) {
7 doTheThing();
8 } else {
9 dontDoTheThing();
10 }
11 } );
12 }, function( error ) {
13 dontDoTheThing();
14 } );