Skip to main content

Open new tab in Chrome extensions



I'm trying to write a simple google extension that will upon clicking "ctrl+alt+x" search for the selected text in google.





This is my mainfest:







{

"name": "A jQuery Chrome extension",

"version": "0.1",

"description": "Use jQuery to build Chrome extensions",

"content_scripts": [

{

"matches" : ["http://*/*"],

"js": ["jquery.js", "jquery.hotkeys.js", "content.js"]

}

],

"background_page": "background.html",

"permissions": [

"tabs"

]

}







And this is my content.js:







$(document).bind('keydown', 'alt+ctrl+x', function() {



var selectedText = window.getSelection().toString();



if (selectedText)

{

var googleQuery = "http://www.google.com/search?q=" + selectedText;

alert(googleQuery);

chrome.tabs.create({"url" : googleQuery});

alert(googleQuery);

}

});







The code works until the line for opening a new tab (the first alert pops up but not the second). I just can't seem to get it working. What am I missing?


Comments

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?