开发者

Object Literal in Firefox extension

I have an extension that needs to pop up a window and then close it.

 var my_ext开发者_Go百科ension = {
    window: null,
    popup: function(){
       my_extension.window = window.open(...)
    },
    close: function(){
       my_extension.window.close()
    }
 }

The popup calls the close function. However, after returning from the open, the my_extension.window is null. I check to make sure it is set in popup. Is another instance of my_extension created when the popup returns?


my_extension is defined in the main browser window, not in the popup. To close the popup from the popup itself, just use window.close

edit: ok, so I guess my_extension.close actually looks something like:

function() {
  // check input from popup window
  if (everythingIsGood) {
    my_extension.window.close()
  }
}

In that case, I would recommend you do that validation in the popup itself. I know, you don't want to put a lot of code in the popup window. And I agree. But you can pass in whatever information is necessary to do the validation (including passing a validation function -- remember that functions are objects too, because JavaScript is cool like that!) when you open the popup. Look for the discussion of window.arguments on this page: https://developer.mozilla.org/en/DOM/window.openDialog

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜