Javascript 使用iframe的谷歌地图不';页面加载后无法工作
我的谷歌地图在我的网站上运行良好:Javascript 使用iframe的谷歌地图不';页面加载后无法工作,javascript,jquery,google-maps,iframe,gtmetrix,Javascript,Jquery,Google Maps,Iframe,Gtmetrix,我的谷歌地图在我的网站上运行良好: <iframe id='iframe1' src="https://maps.google.com/maps?q=25.1954875,-111.6649204&hl=fa;z=14&ie=UTF8&output=embed&hl=en"></iframe> 使用您的代码: <iframe id='iframe1' src="about:blank"></iframe>
<iframe id='iframe1' src="https://maps.google.com/maps?q=25.1954875,-111.6649204&hl=fa;z=14&ie=UTF8&output=embed&hl=en"></iframe>
使用您的代码:
<iframe id='iframe1' src="about:blank"></iframe>
<script>
window.addEventListener("load", function() {
document.getElementById('iframe1').src = 'https://maps.google.com/maps?q=25.1954875,-111.6649204&hl=fa;z=14&ie=UTF8&output=embed&hl=en';
});
</script>
但是,如果
也是动态创建的,那么它也可以工作(请注意,源代码是在附加到DOM之前设置的):
addEventListener(“加载”,函数(){
var iDiv=document.createElement('iframe');
iDiv.id='iframe1';
iDiv.src=https://maps.google.com/maps?q=25.1954875,-111.6649204&hl=fa;z=14&ie=UTF8&output=embed&hl=en';
document.getElementById(“锚”).appendChild(iDiv);
});
代码片段:
addEventListener(“加载”,函数(){
var iDiv=document.createElement('iframe');
iDiv.id='iframe1';
iDiv.src=https://maps.google.com/maps?q=25.1954875,-111.6649204&hl=fa;z=14&ie=UTF8&output=embed&hl=en';
document.getElementById(“锚”).appendChild(iDiv);
});
使用您的代码:
<iframe id='iframe1' src="about:blank"></iframe>
<script>
window.addEventListener("load", function() {
document.getElementById('iframe1').src = 'https://maps.google.com/maps?q=25.1954875,-111.6649204&hl=fa;z=14&ie=UTF8&output=embed&hl=en';
});
</script>
但是,如果
也是动态创建的,那么它也可以工作(请注意,源代码是在附加到DOM之前设置的):
addEventListener(“加载”,函数(){
var iDiv=document.createElement('iframe');
iDiv.id='iframe1';
iDiv.src=https://maps.google.com/maps?q=25.1954875,-111.6649204&hl=fa;z=14&ie=UTF8&output=embed&hl=en';
document.getElementById(“锚”).appendChild(iDiv);
});
代码片段:
addEventListener(“加载”,函数(){
var iDiv=document.createElement('iframe');
iDiv.id='iframe1';
iDiv.src=https://maps.google.com/maps?q=25.1954875,-111.6649204&hl=fa;z=14&ie=UTF8&output=embed&hl=en';
document.getElementById(“锚”).appendChild(iDiv);
});
<iframe id='iframe1' src="about:blank"></iframe>
<script>
window.addEventListener("load", function() {
document.getElementById('iframe1').src = 'https://maps.google.com/maps?q=25.1954875,-111.6649204&hl=fa;z=14&ie=UTF8&output=embed&hl=en';
});
</script>
Refused to display 'https://www.google.com/maps?q=25.1954875,-111.6649204&hl=fa;z%3D14&ie=UTF8&output=embed&hl=en' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
<script>
window.addEventListener("load", function() {
var iDiv = document.createElement('iframe');
iDiv.id = 'iframe1';
iDiv.src = 'https://maps.google.com/maps?q=25.1954875,-111.6649204&hl=fa;z=14&ie=UTF8&output=embed&hl=en';
document.getElementById("anchor").appendChild(iDiv);
});
</script>