2012-04-04 173 views
1

我正在开发一个简单的页面操作扩展在谷歌浏览器中,它有以下目的。如何从谷歌浏览器扩展中弹出内容

  1. 显示弹出窗口,点击并提示输入用户名和密码。
  2. 经过小小的验证后,它应该填写网站的用户名和密码,比如gmail.com。

我看到了一些关于如何在窗口加载时做到这一点的例子,我可以单独做一个弹出窗口。但是我无法从弹出窗口的html中访问父级HTML。

任何帮助将不胜感激。

这里是我的代码的内容。

manifest.json的:

{ 
    "name": "My First Chrome App", 
    "version": "1.0", 
    "description": "Auto fill content", 
    "background": { "scripts": ["background.js"] }, 
    "page_action" : 
    { 
    "default_icon" : "icon-19.png", 
    "default_title" : "Auto Fill", 
    "default_popup" : "test.html" 
    }, 
    "permissions" : [ 
    "tabs" 
    ], 
    "icons" : { 
    "48" : "icon-48.png", 
    "128" : "icon-128.png" 
    }, 
    "manifest_version": 2 
} 

background.js

function checkForValidUrl(tabId, changeInfo, tab) { 
    //checks whether the document contains Steve Jobs 
    if (tab.url.indexOf("gmail")) { 
    chrome.pageAction.show(tabId); 
    } 
}; 
chrome.tabs.onUpdated.addListener(checkForValidUrl); 

的test.html

<html> 
<head> 
    <title> Hi Steve </title> 
    <script type="text/javascript"> 
     function fill() 
     { 
      alert("inside method");   
     } 
    </script> 
</head> 
<body> 
    <form name="userinfo" id="userinfo"> 
     username : 
     <input type="text" name="username"/> 
     password : 
     <input type="password" name="password"/> 
     <input type="button" value="Log In" onclick="fill()";/> 
    </form> 
</body> 
</html> 

感谢, 桑卡

回答

1

创建一个弹出窗口为您的用户名和密码字段的登录。

http://code.google.com/chrome/extensions/browserAction.html#popups

当弹出的形式提交将消息发送到后台页面,然后将消息发送到您的(网页)内容脚本然后其可用于填写并提交表单负责。

http://code.google.com/chrome/extensions/content_scripts.html

你需要了解的消息传递做到这一点:

http://code.google.com/chrome/extensions/messaging.html

+0

非常感谢理查德。如果我遇到任何困难,我会尝试相同的方法并回来。 – Shankar 2012-04-07 17:57:20