Closing Tabs from content script

2,110 views
Skip to first unread message

Hemmer

unread,
Feb 13, 2010, 9:31:45 AM2/13/10
to Chromium-extensions
I'm writing an extension (currently as a content script), and I'm
having trouble with the following section. The trouble is that
"chrome.tabs is not supported in content scripts". What is the
simplest way to get the same functionality? Do I have to use
background.html?

=============== bigbackbutton.js ===============

// fire function if clicked
document.onmousedown = checkPos;

function checkPos(e){

//check if we are on the left edge of window
if(e.pageX == 0){
// LMB goes back
if(e.button == 0){
history.go(-1);

// RMB goes forward
}else if(e.button == 2){
history.go(1);
// MMB closes tab
}else if(e.button == 1){
chrome.tabs.getSelected( null, function(tab)
{ chrome.tabs.remove(tab.id); return true; });
}
}

return true;
}

====================

Finnur Thorarinsson

unread,
Feb 13, 2010, 12:18:39 PM2/13/10
to Hemmer, Chromium-extensions
Yes. This is listed as one of the limitations of the content scripts:
http://code.google.com/chrome/extensions/content_scripts.html

Send a message to your background page and ask it to perform the action on behalf of the content script.



--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Hemmer

unread,
Feb 13, 2010, 7:27:58 PM2/13/10
to Chromium-extensions
Perfect this works a charm. There's only one final thing bugging me
(if am I allowed to continue in this thread?). Basically I want to
suppress the right-click context menu in a particular situation. I've
tried many things including:

window.oncontextmenu = function () { return false; }

I've also tried returning false for the click event handler. This has
really got me stumped, and it's the only thing stopping me from
finishing my first extension.

Thanks, Hemmer

> > To post to this group, send email to chromium-extensi...@chromium.org.


> > To unsubscribe from this group, send email to

> > chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>

Reply all
Reply to author
Forward
0 new messages