1

Hello stackoverflow community. I need ideas and help. Is it possible to remove that pagination from link? for example: http://example.com/comp-filter/page/2/ So i need to remove that page/2/ and i do not know how, because that number can be from 1 to eternity. So what could i do to remove it using jquery or javascript. Help please? For replacing parameters i was using:

function setGetParameter(paramName, paramValue)
{
    var url = window.location.href;
    if (url.indexOf(paramName + "=") >= 0)
    {
        var prefix = url.substring(0, url.indexOf(paramName));
        var suffix = url.substring(url.indexOf(paramName));
        suffix = suffix.substring(suffix.indexOf("=") + 1);
        suffix = (suffix.indexOf("&") >= 0) ? suffix.substring(suffix.indexOf("&")) : "";
        url = prefix + paramName + "=" + paramValue + suffix;
    }
    else
    {
    if (url.indexOf("?") < 0)
        url += "?" + paramName + "=" + paramValue;
    else
        url += "&" + paramName + "=" + paramValue;
    }
    return url;
}

But chaning this code wont help...

2
  • Can you use a regular expression? Commented Nov 19, 2015 at 20:50
  • 1
    jQuery is JavaScript. Commented Nov 19, 2015 at 20:52

1 Answer 1

1

HTML5's history api is what you're looking for.

What you want to do is replaceState.

history.replaceState() operates exactly like history.pushState() except that replaceState() modifies the current history entry instead of creating a new one.

So, your code would be smth like:

history.replaceState(data, document.title, newUrl);

For actual replacement you should try regular expressions:

oldUrl.replace(/page\/\d+\/?/, '');

Best regards, Alexander

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.