--
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.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
On Mon, 2010-08-16 at 07:41 -0700, Peter wrote:
> Well that is exactly what I have come up with, but there is a problem
> with how my background page can see the difference between my
> sendrequest with an url and a sendrequest with my title?
>
> So my background page is:
>
> <html>
> <head>
> <script>
> chrome.extension.onRequest.addListener(
> function(url, sender, sendResponse){
> chrome.tabs.create({url: url}, function(tab){
> chrome.tabs.executeScript(tab.id, {file: "pagechecker.js"});
> });
> sendResponse();
> }
> );
> </script>
> </head>
> </html>
Change the background page JS to:
chrome.extension.onRequest.addListener(
function(url, sender, sendResponse){
// you might consider changing url to
// something else in the above function
if (url.title) {
// do something with url.title
} else if (url.url) {
// do something with url.uri
}
sendResponse();
}
);
>
> And the pagechecker.js:
>
> var title = document.title;
>
> if(document.title != ""){
> chrome.extension.sendRequest(title);
> }
>
Change this to:
var title = document.title;
if (document.title != "") {
chrome.extension.sendRequest({'title':title})
// sends the value of title in an
// object attribute named 'title'
} else {
// do something else, for instance...
chrome.extension.sendRequest({'url':document.url})
// sends the full url of the current document
// in an object attribute named 'url'.
}
> But then it will open up a new tab again, because it think it is a
> sendrequest with a url instead of title. And for full clarification
> this is how the content script in the original tab sends the url:
>
> chrome.extension.sendRequest("http://" + url);
>
> So I could do a javascript match function to see if it is a url or
> not, but I assume this is not the way you should do this?
>
You could do that, but there are some cases where a Web page sets the
title to the URL of the page, which would cause your script to function
in unexpected ways. It'd probably be best to avoid that possibility
altogether.
--
Ben
--
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.