如何在嵌入式Google地图中的KML弹出窗口中覆盖target = _blank? [英] How to override target=_blank in KML popups in embedded Google map?

查看:178
本文介绍了如何在嵌入式Google地图中的KML弹出窗口中覆盖target = _blank?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用KML在Google地图上叠加形状。与每个形状对应的信息包含在< description> 元素中,以及指向与该形状对应的详细信息页面的链接。



例如,我的KML包含以下内容:

 < description> 
<![CDATA [
< div>

...

< p>
< a href =Concession.20.aspx>查看详情< / a>
< / p>
& nbsp;
< / div>
]]>



当然,我想该链接可以在同一个窗口中打开,因为它只是导航到同一网站上的另一个页面。不幸的是,如此处所述,嵌入在< description> KML文件的元素被重写为 target ='_ blank'


当包含在直接写入KML的
HTML中时,目标将被忽略;
打开所有这样的链接,就好像
目标被设置为_blank一样。任何指定的
目标都会被忽略。


我的问题:任何人都可以想到一个可以覆盖这个的解决方法(讨厌的,恕我直言)行为并强制这些链接在同一个窗口中打开?

作为一种方法的例子,我目前正试图覆盖这些链接上的点击事件(使用jQuery),但它们是由Google地图动态生成的,我似乎无法及时得到它们。

解决方案

我已经想出了一个使用jQuery的工作解决方案和地图的 infowindowopen 事件。这是在映射的初始化代码中:

  map = new google.maps.Map2(document.getElementById(map )); 



GEvent.addListener(map,infowindowopen,function(){
//获取对infoWindow的引用
var infoWindow = $(this.getInfoWindow()。getContentContainers());
//在infoWindow中查找所有< a>标记并重置其目标属性
$(a,infoWindow).attr (目标,_self);
});


I'm using KML to overlay shapes on a Google map. Information corresponding to each shape is included in the <description> element, along with a link to a detail page corresponding to that shape.

So for example, my KML includes this:

<description>
    <![CDATA[
    <div>

     ...

        <p>
            <a href="Concession.20.aspx">View details</a>
        </p>
        &nbsp;
    </div>
]]>

Of course, I would like for that link to open in the same window, since it's just navigating to another page on this same site. Unfortunately, as documented here, links embedded in the <description> element of a KML file are rewritten with target='_blank'.

Targets are ignored when included in HTML written directly into the KML; all such links are opened as if the target is set to _blank. Any specified targets are ignored.

My question: Can anyone think of a workaround that would override this (obnoxious, IMHO) behavior and force these links to open in the same window?

As an example of one approach, I'm currently trying to override the click event on these links (using jQuery), but they're generated dynamically by Google maps and I can't seem to get a hold of them early enough.

解决方案

I've come up with a working solution using jQuery and the map's infowindowopen event. This is in the initialization code for the map:

    map = new google.maps.Map2(document.getElementById("map"));

    ...

    GEvent.addListener(map, "infowindowopen", function() {
        // Get a reference to the infoWindow
        var infoWindow = $(this.getInfoWindow().getContentContainers());
        // Find all <a> tags in the infoWindow and reset their target attribute
        $("a", infoWindow).attr("target", "_self");
    });

这篇关于如何在嵌入式Google地图中的KML弹出窗口中覆盖target = _blank?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆