0

I'm using a bookmarklet that lets me share the current URL on Google Plus.

Here's the JavaScript:

javascript:(function(){var w=480;var h=380;var x=Number((window.screen.width-w)/2);
var y=Number((window.screen.height-h)/2);
window.open('https://plusone.google.com/_/+1/confirm?hl=en&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title),'','width='+w+',height='+h+',left='+x+',top='+y+',scrollbars=no');})();

Is there a way to detect the "Sharing Successful" event and call a window.close()? And where do I call it in this JS? Even a pointer in this direction will be appreciated.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Aditya M P
  • 5,127
  • 7
  • 41
  • 72
  • I tried looking at the code for the G+ button in SO (under the fav-star), which has this *exact* functionality. But I only got as far as seeing that clicking the function causes a call to the JS function `d()` with the G+ share URL as a parameter - and what the function does exactly I can't see because the code is minified.. – Aditya M P Apr 04 '12 at 15:50

1 Answers1

1

Is there a way to detect the "Sharing Successful" event and call a window.close()?

No you can't.

Browser security prevents you from using Javascript on one page to interact with another page on a different domain. This is why I can't put up a website that opens your bank's website in an iframe and then controls it.

The Javascript in a bookmarklet is considered to be part of the page that is open when you execute it. So the code becomes part of the page you are adding to Google Plus, and it can not interact with the page from Google because it is on a different domain; and vice versa. The code can open the window, but that is all.

To do what you want would require creating an add-on, extension, or user script.

DG.
  • 3,417
  • 2
  • 23
  • 28