// Share current URL on social media function shareSocial(name) { var url = encodeURIComponent(window.location.href); switch(name) { case "facebook": window.open('https://www.facebook.com/sharer/sharer.php?u=' + url, '_blank'); break; case "twitter": window.open('https://twitter.com/share?ref_src=' + url, '_blank'); break; }; }; // Del n�v�rende side function shareSocial2(name, { text, title, hashtags } = {}) { try { const loc = window.location; const url = (document.querySelector('link[rel=canonical]')?.href || loc.href).split('#')[0]; const enc = encodeURIComponent; const map = { facebook: `https://www.facebook.com/sharer/sharer.php?u=${enc(url)}`, twitter: `https://twitter.com/intent/tweet?url=${enc(url)}${text ? `&text=${enc(text)}` : ''}${hashtags ? `&hashtags=${enc(hashtags)}` : ''}`, linkedin: `https://www.linkedin.com/sharing/share-offsite/?url=${enc(url)}`, email: `mailto:?subject=${enc(title || document.title)}&body=${enc((text ? text + '\n\n' : '') + url)}` }; // Native deling hvis tilgjengelig if (navigator.share && (name === 'native' || !map[name])) { navigator.share({ url, title: title || document.title, text }).catch(()=>{}); return false; } const href = map[name] || map.facebook; // Fors�k 1: a-tag (omg�r noen popup-regler/CSP) const a = document.createElement('a'); a.href = href; a.target = '_blank'; a.rel = 'noopener noreferrer'; document.body.appendChild(a); a.click(); a.remove(); // Fors�k 2: window.open fallback const w = window.open(href, '_blank', 'noopener,noreferrer,width=640,height=640'); if (!w) { // Siste utvei: naviger i samme fane window.location.href = href; } } catch (e) { console.error('shareSocial2 error:', e); } return false; }