DEV Community

Cover image for Sharing options without platforms
Ovi Demetrian Jr
Ovi Demetrian Jr

Posted on

1

Sharing options without platforms

Instead of trying to account for all available options, we should now go with two universal sharing options: “Copy link” and “Send email”.

“Copy link”, would work as a convenient way to copy the current page URL to the visitor’s clipboard. Here is Javascript code that will do that:

async function copyShareLink() {
  let text = window.location.href;

  await navigator.clipboard.writeText(text);
  document.querySelector('#share-link').innerText = "Copied";

  setTimeout(() => {
    document.querySelector('#share-link').innerText = "Copy Link";
  }, 1000);
}
Enter fullscreen mode Exit fullscreen mode

With the HTML that triggers it:

<a onclick="copyShareLink();" id="share-link">Copy Link</a>
Enter fullscreen mode Exit fullscreen mode

And the CSS to make it feel like a link:

#share-link:hover {
  cursor: pointer;
}
Enter fullscreen mode Exit fullscreen mode

“Send email”, uses the oldest standard for sharing a web page, email, which is still commonly used today, and is guaranteed to still be used in the future! You can set it up to launch the visitor’s email app with a new email draft.

Here's HTML + Javascript code that fills out the subject line with the page's title, and in the message includes the URL and the page's meta description, if available:

<a href="javascript:window.open('mailto:?subject='+document.title+'&body='+encodeURIComponent(document.querySelector('meta[name=description]').content)+'%20'+encodeURIComponent(window.location.href));">Send Email</a>
Enter fullscreen mode Exit fullscreen mode

You can see an example of the working code for both of these options at the end of this article's page.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (1)

Collapse
 
ovidem profile image
Ovi Demetrian Jr

Full code available via GitHub.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay