Answer the question
In order to leave comments, you need to log in
How to fix Content Security Policy error when sharing a tweet?
Let's say we have a page with content and a button (link). When you click on the link, the https://twitter.com/intent/tweet window should open where you can share the page.
The problem is that the page did not work. The browser console is full of errors like:
Content Security Policy: The page's settings blocked the loading of a resource at self ("script-src https://connect.facebook.net https://cm.g.doubleclick.net https://ssl.google-analytics. com https://graph.facebook.com https://twitter.com https://*.userzoom.com 'unsafe-eval' https://*.twimg.com https://api.twitter.com ' nonce-L9Fi58Hr8JaO8qnbBZYNCA==' https://analytics.twitter.com https://ton.twitter.com https://syndication.twitter.com https://www.google.com https://t.tellapart. com https://platform.twitter.com https://www.google-analytics.com https://twitter.com ").
var twttr = twttr || {};
tw...
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="tw.js"></script>
</head>
<body>
<a id="a" href="#">tweet</a>
<div>Content ...</div>
</body>
</html>
function myListener(event) {
window.open(
'http://twitter.com/share?text=title&url=http://test.local/tw.php&counturl=http://test.local/tw.php',
'',
'toolbar=0,status=0,width=626,height=436'
);
event.preventDefault();
}
document.addEventListener(
'DOMContentLoaded',
function () {
document.getElementById("a").addEventListener("click", myListener, false);
},
false
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question