How can I add a link in the information window? google-maps-V3

1

I need to create a link inside the information window and click on it, so that it redirects me to a window (div) that would be displayed on the right, how can I do it?

function initMap() {
        var map = new google.maps.Map(document.getElementById('map'), {
            center: new google.maps.LatLng(-25.415896, -54.616280),
            zoom: 12
        });
        var infoWindow = new google.maps.InfoWindow;


        downloadUrl('resultado_gm.php', function(data) {
            var xml = data.responseXML;
            var markers = xml.documentElement.getElementsByTagName('marker');
            Array.prototype.forEach.call(markers, function(markerElem) {
                var name = markerElem.getAttribute('name');
                var address = markerElem.getAttribute('address');
                var id = markerElem.getAttribute('id');
                var type = markerElem.getAttribute('type');
                var point = new google.maps.LatLng(
                    parseFloat(markerElem.getAttribute('lat')),
                    parseFloat(markerElem.getAttribute('lng')));

                var infowincontent = document.createElement('div');
                var strong = document.createElement('strong');
                strong.textContent = name
                infowincontent.appendChild(strong);
                infowincontent.appendChild(document.createElement('br'));

                var text = document.createElement('text');
                text.textContent = address
                infowincontent.appendChild(text);
                infowincontent.appendChild(document.createElement('br'));

                var text2 = document.createElement('text2');
                text2.textContent = id
                infowincontent.appendChild(text2);

                var icon = customLabel[type] || {};
                var marker = new google.maps.Marker({
                    map: map,
                    position: point,
                    icon: icon.icon,
                    draggable: true,
                    animation: google.maps.Animation.DROP
                });
                marker.setAnimation(google.maps.Animation.BOUNCE);
                marker.addListener('click', function() {
                    infoWindow.setContent(infowincontent);
                    infoWindow.open(map, marker);
                });
            });


        });
    }



    function downloadUrl(url, callback) {
        var request = window.ActiveXObject ?
            new ActiveXObject('Microsoft.XMLHTTP') :
            new XMLHttpRequest;

        request.onreadystatechange = function() {
            if (request.readyState == 4) {
                request.onreadystatechange = doNothing;
                callback(request, request.status);
            }
        };

        request.open('GET', url, true);
        request.send(null);
    }

    function doNothing() {}

    /////era para regargar los marcadores pero aun no funciona
google.maps.event.trigger(map, 'resize');
        ////////
    
asked by franmavazq 06.11.2017 в 12:35
source

1 answer

0

If I understand correctly, all you have to do is create a link and give it a target="_blank" to open in a new window / tab.

var enlace = document.createElement('a');
enlace.textContent = "texto del enlace";
enlace.href = "URL-DEL-ENLACE";
enlace.target = "_blank"; // para que se abra en una nueva pestaña
infowincontent.appendChild(enlace);
    
answered by 06.11.2017 / 18:39
source