开发者

Gmaps4rails custom info window with javascript content

I'm using gmaps4rails and I need to execute javascript inside a marker's info window. Every marker's underlying object has a sound file associated with it, and I want to be able to play that file inside the info window. The player I'm using is jwplayer and it is instantiated with javascript call with few params.

I've tried to use the gmaps4rails own method to insert the code into info window like below

def gmaps4rails_infowindow
  "<div id='jwplayer_#{self.id}'>Here comes the player...</div>
    <script type=\"text/javascript\">
      //<![CDATA[
        jwplayer(\"jwplayer_#{self.id}\").setup(#{options});
      //]]>
   </script>"
end

but that doesn't work. Actually anything with a < script> tag inside that method seems to break the gmap4rail开发者_运维百科s map loading anyway I try it.

Is there a way to get javascript executed inside the info window by using gmaps4rails, or do I need to roll some other solution for that?


You won't be able to add any <script> in gmaps4rails (as well as raw google maps API I guess).

You should deal with this problem using click event on the marker + close event of infowindow.

Use the callbacks to add these functions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜