views:

631

answers:

1

I want to create an extension that redirects the user to another website if he clicks on the extension button. So far I have only seen extensions which create a new tab for each click.

Is it possible to redirect the user to another website using the active tab?

I tried something like this:

chrome.browserAction.onClicked.addListener(function(tab) {
    var url = "https://www.mipanga.com/Content/Submit?url="
        + encodeURIComponent(tab.url)
        + "&title=" + encodeURIComponent(tab.title);

    document.location.href = url; // <-- this does not work
});
+4  A: 

How about something like this?

chrome.tabs.getCurrent(function (tab) {
  var tabUrl = encodeURIComponent(tab.url);
  var tabTitle = encodeURIComponent(tab.title);
  chrome.tabs.update(tab.id, {url: "https://www.mipanga.com/Content/Submit?url=" + tabUrl + "&title=" + tabTitle});
});
Dan Atkinson

related questions