如何使用Google Chrome扩展程序&内容脚本? [英] How do I redirect to a URL using a Google Chrome Extension & Content Script?

查看:119
本文介绍了如何使用Google Chrome扩展程序&内容脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在构建Google Chrome浏览器扩展程序,该扩展程序会测试某些模式,如果找到,它们会将其重定向到新的网址。

I'm currently building a Google Chrome extension which tests for certain patterns and if found, redirects them to a new URL.

我已经获取了模式检查通过内容脚本完成,现在我不知道如何才能继续完成重定向。任何建议?

I've gotten the pattern checking done via a content script, and now I'm not sure how can I proceed with getting the redirect done. Any suggestions ?

推荐答案

将内容脚本中的重定向网址发送到后台页面:

Send redirect url from a content script to a background page:

chrome.runtime.sendMessage({redirect: "http://redirect"});

在会导致重定向的后台页面更新标签页中:

In a background page update tab's url which would cause redirect:

chrome.runtime.onMessage.addListener(function(request, sender) {
    chrome.tabs.update(sender.tab.id, {url: request.redirect});
});

这篇关于如何使用Google Chrome扩展程序&内容脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆