Google+ Share in JavaScript

Google+ Share in JavaScript

Google+ Share in JavaScript

As of April 2019, Google+ was officially shut down for consumers, and the Google+ Share button was deprecated. Therefore, you can no longer use the official Google+ sharing functionality to share content directly to Google+. However, if you're looking to implement sharing to other Google services or social platforms, alternatives such as Google Hangouts, Gmail, or Google Drive can be used.

If you're looking for how to implement social sharing buttons, I can provide an example of how you might use Google's sharing services, or how to implement sharing buttons for other platforms like Facebook, Twitter, etc. Here's an overview of how the Google+ Share button used to work and alternatives to enable sharing features.

Old Google+ Share Button (Deprecated)

Previously, Google+ provided a method for sharing content directly to a user's Google+ feed using a special <script> for embedding a Google+ Share button:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Google+ Share Example</title> <script src="https://apis.google.com/js/platform.js" async defer></script> </head> <body> <!-- Google+ Share Button --> <div class="g-plus" data-action="share" data-annotation="none"></div> <script> window.onload = function() { gapi.plusone.go(); }; </script> </body> </html>

Explanation:

  • The g-plus button was used to allow users to share a page to their Google+ stream.
  • The gapi.plusone.go() function initialized the share button.

Alternative: Google Drive or Gmail Share

Since Google+ is no longer active, you can use other Google services like Gmail or Google Drive for sharing content. Here's an example of how you might create a Gmail share button using a simple mailto link:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Gmail Share Example</title> </head> <body> <a href="mailto:?subject=Check%20this%20out&body=I%20found%20this%20interesting%20link:%20http://example.com" target="_blank">Share via Gmail</a> </body> </html>

Explanation:

  • The mailto link allows users to open their Gmail account with a pre-filled subject and body, including the content you want to share.

Other Social Media Sharing (Using JavaScript)

Instead of Google+, you can implement sharing to other platforms such as Facebook, Twitter, LinkedIn, etc. Here's how you might implement those:

Twitter Share Button (Using JavaScript)

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Twitter Share Example</title> </head> <body> <!-- Twitter Share Button --> <a href="https://twitter.com/share?text=Check%20out%20this%20website&url=http://example.com" target="_blank">Share on Twitter</a> </body> </html>

Facebook Share Button (Using JavaScript)

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Facebook Share Example</title> <script async defer src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v12.0"></script> </head> <body> <div class="fb-share-button" data-href="http://example.com" data-layout="button_count"> </div> </body> </html>

LinkedIn Share Button (Using JavaScript)

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>LinkedIn Share Example</title> <script src="https://platform.linkedin.com/in.js" type="text/javascript"></script> </head> <body> <script type="IN/Share" data-url="http://example.com"></script> </body> </html>

Conclusion

Since Google+ has been discontinued, the Google+ Share button is no longer supported. However, you can use other methods like Gmail (mailto), Google Drive, or third-party sharing buttons (for Facebook, Twitter, LinkedIn, etc.) to allow users to share content from your site.

If you're still trying to create social media share buttons, I recommend integrating with the official APIs of Facebook, Twitter, and others, or using libraries like ShareThis or AddThis for a simplified solution.

Soeng Souy

Soeng Souy

Website that learns and reads, PHP, Framework Laravel, How to and download Admin template sample source code free.

Post a Comment

CAN FEEDBACK
close