URL redirection Google extension

Asked

Viewed 395 times

0

I have a silly problem, but I can’t solve it.

Come on:

I want to adapt this code

var pattern=/\bBloqueado/;
var viewtext = "http://www.google.com";
var newurl;
if (pattern.test(window.document.title))
{
newurl = viewtext;
chrome.extension.sendRequest({redirect: newurl});

}

It sees if the page title is spelled "Blocked" and if it is redirected to http://www.google.com

I need something to check if the Url is exactly google.com and if you’re going to redirect to google.com and if it’s google.com stop and do nothing.

Someone can help me?

1 answer

2


I think it helps you:

var padrao = /^(http:\/\/|https:\/\/)?(www\.)?google\.com(\/)?$/g;
var url    = "http://google.com/";

if (padrao.test(window.document.location.href)) {
    chrome.extension.sendRequest({redirect:url});
}
  • Good afternoon, so that the snippet if the code only runs on extensions?

Browser other questions tagged

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