Google Chrome扩展程序重定向不同页面

时间:2013-07-24 08:56:41

标签: javascript google-chrome google-chrome-extension google-chrome-app

我有popup.html我想在用户点击href时在扩展名中加载不同的html页面。示例用户将输入用户名和密码,如果正确,则login.html重定向到内容。

试过这个:

window.onload=function(){
$( '#Login' ).click(function() { 
    alert('test');  
        chrome.browserAction.setPopup({
            popup:"login.html"
            });

});
}

登录是一个按钮。但是login.html没有显示出来。警报正在运行。

2 个答案:

答案 0 :(得分:0)

要更改弹出式html页面,您可以使用

chrome.browserAction.setPopup

此页面上的更多详细信息http://developer.chrome.com/extensions/browserAction.html

你可以这样做:

in html:

<a onclick="changePopup();" href="#"> change popup</a>

在js:

function changePopup(){
    chrome.browserAction.setPopup({
       popup:"second_page.html"
    });
}

您没有指定链接放在哪里?在弹出页面或html页面中,所以我假设链接被放置在弹出式html页面中。

如果链接位于扩展名之外,则应使用内容脚本https://developer.chrome.com/extensions/content_scripts.html

更新:您应该使用背景页面或事件页面将java脚本文件放在manifest.json中,具体取决于您的需要。

在这里您可以找到更多信息:

https://developer.chrome.com/extensions/background_pages.html

http://developer.chrome.com/extensions/event_pages.html

....
  "background": {
    "scripts": ["background.js"]
  },
....

如果您使用<script>标记从html页面加载了javscript文件,则应使用Message传递api:http://developer.chrome.com/extensions/messaging.html与您的html进行交互。

答案 1 :(得分:0)

试试这个

<a href="another-page.html"><button id="add-button">Go to another popup</button></a>

相关问题