I just found another method that seems to answer my question:
How to access parent iframe from javascript
Embedding a script in an iframe allows you to find it at any time, since the script always refers to its own window.
I believe this is the best approach, as it will always work no matter how many times you add a script to the page (think of widgets). You can comment.
What prompted me to consider iframes, first of all, it was an experiment that I did to create a Google gadget.
Christophe
source share