Remove action in window.Location

Asked

Viewed 43 times

0

I am creating a comparison that will do the following, if the address is www.google.com will perform the function otherwise it will remove. I’m with this script but I’m not getting to mount Else.

if (window.location.host == 'http://www.google.com') {
    var optinBtn = document.querySelector('#newsletterButtonOK'),
        clickFnc = document.querySelector('#newsletterButtonOK').onclick;

    window.optinHandler = function () {
        Bat.cookie.set('allin-optin', document.querySelector('#newsletterClientEmail').value, 60);
        clickFnc();
    };

    optinBtn.setAttribute('onclick', 'window.optinHandler()');
} 
else {

}
  • Remove what? you’d better use a .match(REGEX) than a simple comparison == which will validate only 1 possibility.

1 answer

0


You can use a "History method"

window.history.pushState(window.location.host, "Titulo", "/NovaUrl");

This method will override the URL.

Check out the documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.