views:

55

answers:

1

I am creating an extension that will launch an external script based on highlighted text. So, far, the script works, except I am having issues closing the newly created window.

In my background.html, I have the following:

<script>
function executeScript(selection) {
  var queryText = 'script:' + selectedText;
  chrome.tabs.create({url: queryText});
  chrome.tabs.getSelected(null, function(tab) {
    chrome.tabs.remove(tab.id);
  });
}
</script>

My problem is with the setup above, it closes the tab before the "url" loads, so it never executes the script.

If I take out the getSelected lines (lines 5-7), it opens the tab and runs the script perfectly. I am trying to just get the syntax to close the tab automatically after it executes.

Thanks!

A: 

Not exactly sure what you are trying to accomplish, but if you want to close a tab after a script has run you should have the script send a "Close Me" request to background.html using chrome.extension.sendRequest.

You might be better off using chrome.tabs.executeScript, which allows you to pass a function (in which you could close the tab) which gets called after the script has finished running.

MooGoo
Basically, right now the tab flashes open then closes, but I need the script to wait until the "script:foo" url is loaded...
Tribalcomm
What kind of URL is "script:foo"? Do you mean "javascript:foo"?
MooGoo
Tribalcomm