Search code examples
javascriptgoogle-chromedom-eventsbookmarklet

How do I detect the Google+ "share task complete" in Javascript and close Chrome Bookmarklet?


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.


Solution

  • 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.