Google地图内的iframe不加载 [英] Google Maps inside iframe not loading

查看:85
本文介绍了Google地图内的iframe不加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个奇怪的问题,我不知道问题是什么。以下jQuery代码是我想实现的简化版本:

  var iframe = $('< iframe /> ;'); 
iframe.prop('src','https://maps.google.com/maps?q=London&hl=zh-TW&sll=37.0625,-95.677068&sspn=46.677964,93.076172&t= H&安培; hnear =伦敦,+美国+英国&安培; Z = 10' );
iframe.appendTo($('body'));

// iframe加载时:
iframe.load(function(){
alert(1);
});

映射从不加载, load()事件。 Chrome报告了以下错误:

拒绝显示'https://maps.google.com/maps?q=London&hl=zh-CN& ;因为它将'X-Frame-Options'设置为'SAMEORIGIN',所以在一帧中sll = 37.0625,-95.677068& sspn = 46.677964,93.076172& t = h& hnear =伦敦,+ United + Kingdom& z = 10'

这是一个 jsFiddle demo

解决方案

& output = embed
附加到URL末尾可以解决问题。


I ran into a strange issue, and I don't know what the problem is. The following jQuery code is a simplified version of what I want to achieve:

var iframe = $('<iframe />');
iframe.prop('src', 'https://maps.google.com/maps?q=London&hl=en&sll=37.0625,-95.677068&sspn=46.677964,93.076172&t=h&hnear=London,+United+Kingdom&z=10');
iframe.appendTo($('body')); 

// When the iframe loads:
iframe.load(function() {
    alert(1);
});

The map is never loaded, and the load() event is never triggered. Chrome reports the following error:

Refused to display 'https://maps.google.com/maps?q=London&hl=en&sll=37.0625,-95.677068&sspn=46.677964,93.076172&t=h&hnear=London,+United+Kingdom&z=10' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

How does one bypass this?

Here's a jsFiddle demo.

解决方案

Appending &output=embed to the end of the URL fixes the problem.

这篇关于Google地图内的iframe不加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆