首页 > 解决方案 > 从函数设置 src 时,iframe HTML 标记拒绝连接

问题描述

我正在尝试使用函数查找纬度和经度。然后使用这些值在 iframe 中设置 src 以在 Google 地图中显示位置。但谷歌拒绝连接。当从 iframe 设置相同的“src”时,它可以工作。两者是相同的,只是函数动态生成 src。为什么它不起作用以及如何使它起作用?

    </script>
         .....
            function showPosition(position){
            lat = position.coords.latitude;
            long = position.coords.longitude;
            lin = "https://maps.google.com/maps?q="+lat+","+long+"&hl=es;z=14&amp;output=embed";
            fh.innerHTML = lin;
            document.getElementById('pmap').src = lin;
        }
    </script>
    
    <iframe 
    id = "pmap" width="600" height="450" 
    src = "https://maps.google.com/maps?q=25.6552912,88.6423475&hl=es;z=14&amp;output=embed">
   </iframe>

标签: javascripthtmliframe

解决方案


推荐阅读