Tweet button and infoWindow

我的梦境 提交于 2019-12-22 14:05:32

问题


I want to integrate Tweet button into a Google Maps v3 infoWindow (infoBox), with I have no success. Of course the script I use works on a simple page. I set up the twitter's js in my template file, added anchor to the html variable in the gmaps javascript file: ... Tweet ...

What now can be see is only the "Tweet" text if I hover over the anchor link, and no Tweet grapic button is visible. If I click on this button, Twitter site loads but shares nothing.

With Facebook Like button I had to implement a line of code, whet the "domready" event runs.

How to do it Twitter?


回答1:


I'm having the same problem but am getting closer to solving it.

I'm guessing you're using the standard Twitter examples where you add an <a> tag like:

<a href="https://twitter.com/share" class="twitter-share-button" 
data-lang="en">Tweet</a>

And then need to get their JavaScript to load:

<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
js.src="//platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js,fjs);
}}(document,"script","twitter-wjs");</script>

So the problem is likely that the infoWindow isn't getting attached to the DOM.

The Google Maps V3 API InfoWindow Class has an Event "domready".

So if you're using jQuery like I am then you need to do something like:

google.maps.event.addListener(bubble, 'domready', function(event) {
        !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
        if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
        js.src="//platform.twitter.com/widgets.js";
        fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
});

Bearing in mind that I haven't got this to work yet :)

Let's sort this sucker out!




回答2:


Just change infobox for whatever is named your InfoWindow object, gyaresu answer is ok, but it will only work once.

google.maps.event.addListener(infobox, 'domready', function(event) {
    FB.XFBML.parse();
    twttr.widgets.load();
});


来源:https://stackoverflow.com/questions/9802065/tweet-button-and-infowindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!