News details
Penny Grow News Details Page
Share
// Get current page URL and title
const currentUrl = window.location.href;
const currentTitle = document.title;
function shareOnFacebook() {
window.open(`https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(currentUrl)}`, '_blank', 'width=600,height=400');
return false;
}
function shareOnTwitter() {
window.open(`https://twitter.com/intent/tweet?url=${encodeURIComponent(currentUrl)}&text=${encodeURIComponent(currentTitle)}`, '_blank', 'width=600,height=400');
return false;
}
function shareOnLinkedIn() {
window.open(`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(currentUrl)}`, '_blank', 'width=600,height=400');
return false;
}
function copyToClipboard() {
navigator.clipboard.writeText(currentUrl).then(() => {
// Show copied feedback
const tooltip = document.querySelector('.social-icon.copylink .tooltip');
if (tooltip) {
tooltip.textContent = 'Copied!';
setTimeout(() => {
tooltip.textContent = 'Copy link';
}, 2000);
}
}).catch(err => {
console.error('Failed to copy: ', err);
// Fallback for older browsers
const textarea = document.createElement('textarea');
textarea.value = currentUrl;
document.body.appendChild(textarea);
textarea.select();
try {
document.execCommand('copy');
const tooltip = document.querySelector('.social-icon.copylink .tooltip');
if (tooltip) {
tooltip.textContent = 'Copied!';
setTimeout(() => {
tooltip.textContent = 'Copy link';
}, 2000);
}
} catch (err) {
console.error('Fallback copy failed: ', err);
}
document.body.removeChild(textarea);
});
return false;
}
sign up our newsletter
Sign up today for hints, tips and the latest product news - plus exclusive special offers.
Discover more from CyberHeroes
Subscribe to get the latest posts sent to your email.