How to get page title?

933 views
Skip to first unread message

Arpit

unread,
Oct 2, 2010, 4:54:50 PM10/2/10
to Chromium-extensions
Hi,

This is regarding Context Menu APIs. I am looking for the way to get
the title of current page, in the same manner as we can get its URL by
using pageUrl (ref: http://code.google.com/chrome/extensions/beta/contextMenus.html).

Thanks. :)

PhistucK

unread,
Oct 3, 2010, 2:37:41 AM10/3/10
to Arpit, Chromium-extensions
You cannot do it in the same way, you have to inject a script into the tab (either a content script or by using chrome.tabs.executeScript), you can use the Tab argument to identify the tabs to which you need to inject the script using chrome.tabs.executeScript, or to which you need to send a message (in case you are using a content script).
Within the injected script, use message passing to pass the information to the background page by using chrome.extension.sendRequest({title: document.title}, function(){}) to send the title to the background page (in which you should receive the message with chrome.extension.onRequest.addListener).

PhistucK




--
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.


TobiFromBavaria

unread,
Oct 3, 2010, 1:52:29 PM10/3/10
to Chromium-extensions
The second parameter of the onclick function is the tab.
http://code.google.com/chrome/extensions/tabs.html#type-Tab

TobiFromBavaria

unread,
Oct 4, 2010, 3:14:59 PM10/4/10
to Chromium-extensions
You are wrong. Content scripts are not necessary to get the title of a
tab. A object of the Tab type can have a "title" attribute.
http://code.google.com/chrome/extensions/tabs.html#type-Tab
The title attribute may be missing when the page is still loading.

PhistucK

unread,
Oct 4, 2010, 3:36:26 PM10/4/10
to TobiFromBavaria, Chromium-extensions
Wow. Thank you for enlightening me, I did not know that. I will try to remember it next time.
Sorry for giving out false information.

PhistucK




--
Reply all
Reply to author
Forward
0 new messages