sharetodiaspora / sharetodiaspora.github.io

diaspora* Advanced Sharer - Share links and posts to your favorite diaspora* pod.
sharetodiaspora.github.io
GNU Affero General Public License v3.0
23 stars 12 forks source link

Closing popup #2

Closed simonrenoult closed 10 years ago

simonrenoult commented 10 years ago

Hi,

I would like to know how the Diaspora sharer > Sharing buttons works, especially this snippet :

<a href="javascript:window.open('http://sharetodiaspora.github.io/?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title),'das','location=no,links=no,scrollbars=no,toolbar=no,width=620,height=550');">
    <img src="https://joindiaspora.com/favicon.ico" style="border: 0px solid;" />
</a>

Basically, I'm working on my own sharer but I can't figure out how a popup can close itself. The workflow is supposed to be like this I guess :

  1. Click on the share button
  2. Grab the data on the page
  3. Open a popup contacting the "share manager" of my service
  4. Pass the data to the share manager as query parameters (GET)
  5. Render the data read and offer to validate or cancel
  6. Validate (by the user) + share or cancel
  7. Close the popup

Steps 1 to 6 are straight forward but I can't figure out how to process 7, since the script in the popup has not created the popup, it won't be allowed to close it (as stated in the documentation).

How and where did you do that ? Any help would be greatly appreciated!

fdavidcl commented 10 years ago

I am pretty sure there's a window.close() call on Diaspora's bookmarklet page. The window.close() function is only allowed if the window was opened by a script, but not necessarily the same script or even in the same server. From MDN, "Scripts may not close windows that were not opened by script."

So, my sharing button code has a window.open() call, that allows Diaspora's bookmarklet to close itself, and I think that's it.