function urlWithPageNum(url, pageNum, paramNameForPage) {
        var query = getQuery(url);
        var regex = new RegExp('(^|&|\\?)' + paramNameForPage + '=[^&]+');
        var result = regex.exec(query);
        if (result) {
            // if paramNameForPage parameter already exists, update it.
            query = query.replace(regex, result[1] + paramNameForPage + '=' + pageNum);
        } else {
            // if not add new one.
            query = query + '&' + paramNameForPage + '=' + pageNum;
        }

        return urlWithQuery(url, query);
    }
urlWithPageNum

Create a url whose query has a paramNameForPage parameter whose value is
pageNum.

@param {String} url
@param {Number} pageNum
@param {String} paramNameForPage