如何验证谷歌地图嵌入代码iframe?

时间:2016-09-14 11:13:20

标签: javascript php html google-maps iframe

我已经搜索过这个主题,但遗憾的是找不到答案。

有没有办法验证Google地图嵌入代码iframe?就像用户将代码粘贴到文本框中并单击按钮一样,系统会检查该代码是否有效。或解析代码并检查模式是唯一的方法?

提前感谢您的任何帮助或想法。

2 个答案:

答案 0 :(得分:2)

Google正在为您提供正确的代码。我一直用它来为我朋友的房地产网站。使用响应式iframe代码也可以适应所有不同的屏幕尺寸。使用此代码,更改iframe源以满足您的需求。

/* Flexible iFrame */

.Flexible-container {
  position: relative;
  padding-bottom: 56.25%;
  padding-top: 30px;
  height: 0;
  overflow: hidden;
}
.Flexible-container iframe,
.Flexible-container object,
.Flexible-container embed {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
<!-- Responsive iFrame -->
<div class="flexible-container">
 <!-- Responsive iFrame -->
<div class="flexible-container">
<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d1457.0935074158538!2d-70.75659948473937!3d43.07956346598421!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0xb5e8c11925c54ab4!2sSamonas+Realty+Llc!5e0!3m2!1sen!2sus!4v1402966179098" width="600" height="450" frameborder="0" style="border:0"></iframe>
</div>
</div>

答案 1 :(得分:0)

为了记录,我搜索了匹配iframe google嵌入代码的正则表达式。

我发现了这个问题:PHP - Regex to check if <iframe> comes from Google Maps

并修改了正则表达式:

<iframe\s*src="https:\/\/www\.google\.com\/maps\/embed\?[^"]+"*\s*[^>]+>*<\/iframe>

希望帮助有同样问题的人。 :D谢谢大家!

相关问题