Chrome Extension: Create a new tab by click a button
I am a starter to build a Chrome extension. Now I have an issue that I
used the function described in Chrome extension developer doc to make a
button creating a new tab in "popup.html". But it cannot work no matter
which methods I tried from stackoverflow mentioned. My codes are
following:
<html>
<head>
<title>Facebook Connect For Chrome Extension</title>
<script type="text/javascript" src="background.js"></script>
<script type="text/javascript" src="popup.js"></script>
<script>
function showIndex(){
var index_url="/index.html",
chrome.tabs.create({
url: index_url
}),
}
</script>
<body>
<button value="tab" style="width:100px; height:100px;"
onclick="showIndex();">Go to Index</button>
</body>
or
function createTab() {
chrome.tabs.create({url: "/index.html"});
}
<a href="#" onclick="creatTab();">Go to Index</a>
Neither of them can work.
So I wonder whether should this function be stated in background.js? If
not, please tell me what's wrong with these code. Thanks in advance!
BTW I changed the url to like "www.stackoverflow.com" It is still the
same---not working.
Any ideas or advices will be appreciated. Thank you!
No comments:
Post a Comment