从js文件调用thickbox

时间:2021-01-14 16:03:42

Hi i am trying to add thick box to a overlay in googlemaps. On my JQuery onload function i call the following function. The map works fine. But when the thick box doesn't seem to be called. This is the line that does work

嗨,我想在googlemaps中添加厚框到叠加层。在我的JQuery onload函数上,我调用以下函数。地图工作正常。但是当厚盒子似乎没有被召唤时。这是有效的线

<a href="test.html?keepThis=true&TB_iframe=true&height=250&width=400" title="add a caption to title attribute / or leave blank" class="thickbox">Example 1</a>

The whole function

整个功能

function load(lat, lng, zlevel, userKey, state) {

        map = new GMap2(document.getElementById("map"));
        map.disableDoubleClickZoom();
        map.setCenter(new GLatLng(lat, lng), zlevel);

        if (state) {

            dsp = true;

            map.addControl(new GLargeMapControl());
            GEvent.addListener(map, "click", function(overlay, latlng) {

                var zoom = map.getZoom();
                var display = '<h5 class="header-flag">Flag</h5><p class="maptext"><a href="#" onclick="javascript:openOverlay(' + latlng.lat() + ',' + latlng.lng() + ',' + zoom + ');">Click here</a> to enter your comment - 
<a href="test.html?keepThis=true&TB_iframe=true&height=250&width=400" title="add a caption to title attribute / or leave blank" class="thickbox">Example 1</a></p>';

                setTimeout(function() { map.openInfoWindowHtml(latlng, display, { maxWidth: 200 }); }, 0);
            });
        } else {


        }

        mgr = new MarkerManager(map);
        loadMarkers(userKey);
        mgr.refresh();
    }

1 个解决方案

#1


Your adding the link that you want to activate the thickbox to the DOM after the thickbox function has already been called. This is because you are creating the link dynamically within the map.openInfoWindowHtml function. You need to call the thickbox function after this function has been executed.

在调用thickbox函数后,将要激活thickbox的链接添加到DOM。这是因为您在map.openInfoWindowHtml函数中动态创建链接。执行此功能后,需要调用thickbox函数。

Trouble is I just looked at the thickbox docs and thickbox gets set up within the thickbox.js file as soon as the DOM loads which is too soon for you. You could try to alter the setTimeout function to this:

麻烦的是,我只是看了一下thickbox文档,并且只要DOM加载了,就会在thickbox.js文件中设置thickbox,这对你来说太早了。您可以尝试将setTimeout函数更改为:

setTimeout(function() { map.openInfoWindowHtml(latlng, display, { maxWidth: 200 }); tb_init('a.thickbox'); }, 0);

I cant be 100% sure this will work, but this is the crux of the problem.

我不能100%肯定这会起作用,但这是问题的症结所在。

#1


Your adding the link that you want to activate the thickbox to the DOM after the thickbox function has already been called. This is because you are creating the link dynamically within the map.openInfoWindowHtml function. You need to call the thickbox function after this function has been executed.

在调用thickbox函数后,将要激活thickbox的链接添加到DOM。这是因为您在map.openInfoWindowHtml函数中动态创建链接。执行此功能后,需要调用thickbox函数。

Trouble is I just looked at the thickbox docs and thickbox gets set up within the thickbox.js file as soon as the DOM loads which is too soon for you. You could try to alter the setTimeout function to this:

麻烦的是,我只是看了一下thickbox文档,并且只要DOM加载了,就会在thickbox.js文件中设置thickbox,这对你来说太早了。您可以尝试将setTimeout函数更改为:

setTimeout(function() { map.openInfoWindowHtml(latlng, display, { maxWidth: 200 }); tb_init('a.thickbox'); }, 0);

I cant be 100% sure this will work, but this is the crux of the problem.

我不能100%肯定这会起作用,但这是问题的症结所在。