map.graphics.enableMouseEvents(); dojo.connect(map.graphics, "onClick", function(evt) { map.infoWindow.setContent("<span id='spanSelectPDF'></span><span><input type='button' value='Open PDF' onclick='openPDF();' /></span>"); var URLs = evt.graphic.attributes.PDFs.split(";"); // Assumes attribute's name is 'PDFs' if (URLs.length > 1) { // More than 1 pdf, so use a select list... var selectList = $("<select id='selectPDF' />"); selectList.append($("<option selected='selected'>Select PDF</option>")); for (var i = 0; i < URLs.length; i++) { var url = URLs; selectList.append($("<option value='" + url + "'>" + url + "</option>")); } $("#spanSelectPDF").append(selectList); } else { // One (or fewer) pdfs, just put the URL in the span to display $("#spanSelectPDF").html(URLs[0]); } });
function openPDF() { var url; if ($("#selectPDF").length > 0) // Check if the select list exists url = $("#selectPDF").find("option:selected").val(); // get the value of the selected option else url = $("#spanSelectPDF").html(); // otherwise use the html we stuck in the span as the link if (url != "") // Check the url has a value, as our default option has no value (requires that the user make a selection) window.open(url); // Open the link }
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.