var url = window.href.toString(); var id = url.match(/\?page=(\d+)/); if (id[1]) { alert('The ID is: ' + id[1]); } else { alert('No ID found'); }