I have two twitter share button , one on body and another inside a bootstrap modal.
Both Share button works on chrome but not on Firefox. On Firefox the first share button which is out side modal is working but when I open the modal I can’t see the share button.
Is it a bug? Is there any workaround for this problem?
Here is my code
https://jsfiddle.net/swarnendu/fb7t0fpe/3/embedded/result/
<html>
<head>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<script>
window.twttr = (function (d,s,id) {
var t, js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;
js.src="https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });
}(document, "script", "twitter-wjs"));
</script>
<div class="row">
<a class="twitter-share-button" href="https://twitter.com/intent/tweet" target="_self">Tweet</a>
</div>
<div class="container">
<h2>Modal Example</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<a class="twitter-share-button"
href="https://twitter.com/intent/tweet" target="_self">
Tweet</a>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
2
Answers
It looks like a bug, because the widget button is hidden in the Firefox and this css provided by Twitter. However, I have found workaround for that – basically you can create the missing button by yourself.
1) Change contents of
modal-body
div like this:2) Add following styles to your page:
3) Add jQuery event handlers
That’s it. So now you have buttons in FF and Chrome inside popup window. You can adjust the styles for button and icon to make it looks better, if necessary.
Working example:
http://plnkr.co/edit/LPyveKju0zQAELpOzkQW?p=preview
Hope this helps.
Or just go ahead and clone the button with jQuery:
https://jsfiddle.net/jonathanzuniga/k2nk651d/