Chrome扩展程序:打开标签页,转到网址,填写表单并提交表单 [英] Chrome Extension: Open tab, go to url, fill form and submit form

查看:180
本文介绍了Chrome扩展程序:打开标签页,转到网址,填写表单并提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照这里的教程
http://www.blackweb20.com/2010/01/11/creating-your-own-google-chrome-extension/

我可以打开一个带有自定义扩展的选项卡,并加载一个URL,我想填写并提交一个表单与JavaScript在打开的页面。例如,我可以在google.com上提交搜索吗?

I can open fine a tab with a custom extension and load a url, and I would like to fill and submit a form with javascript on the page opened. For example, could I submit a search on google.com?

这里是我到目前为止:

manifest.json
{
  "name": "My First Extension",
  "version": "1.0",
  "description": "The first extension that I made.",
  "browser_action": {
    "default_icon": "icon.png"
  },
  "background_page": "background.html",
  "permissions": [
    "tabs"
  ]
}

background.html

background.html

<script>

// get tab http://stackoverflow.com/questions/1979583/how-can-i-get-the-url-for-a-google-chrome-tab


chrome.browserAction.onClicked.addListener(function(tab) {
  chrome.tabs.create({'url': "http://google.com"}, function(tab) {
    // Tab opened. Wait until page loads, from here it is not working
    jQuery(document).ready(function() {
        jQuery('#tsf').submit();
        });
  });
});
</script>


推荐答案

您的jQuery代码正在后台页面执行新标签页。尝试使用 chrome.tabs.executeScript 在tab环境。

Your jQuery code is getting executed in the background page not the new tab. Try using chrome.tabs.executeScript to execute the submit in the tab environment.

这篇关于Chrome扩展程序:打开标签页,转到网址,填写表单并提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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