如何在iframe中访问URL的参数?

时间:2015-02-25 16:10:16

标签: javascript html url iframe openlayers

我有以下带有jQuery代码的HTML:

<div id="info" style="width: 100%; height: 280px; overflow-y: scroll;"></div>

var url1 = cbcWMS1.getGetFeatureInfoUrl
(evt.coordinate, viewResolution, 'EPSG:3857', {'INFO_FORMAT': 'text/html'});

$('#info').append('<iframe width="99%" seamless src="' + url1 + '"</iframe>');

字符串url1返回带有元素的表的iframe元素。

如何访问iframe

中的元素

我想添加一个条件,如果iframe缺少内容,则可以使用jQuery隐藏整个<div id='info'>

字符串:url1包含以下代码:

<body>
<table class="table table-hover table-condensed">
<h3>${type.name}</h3>
<head>
  <tr>
    <#list type.attributes as attribute>
      <#if !attribute.isGeometry> 
        <th>${attribute.name}</th> 
      </#if>
    </#list> 
  </tr>
</head>

<body>
  <#assign odd = false>
    <#if odd>
      <tr class="odd">
    <#else>
      <tr>
    </#if>
  <#assign odd = !odd>

  <#list features as feature>
    <#list feature.attributes as attribute>
      <#if !attribute.isGeometry>
        <td>${attribute.value}</td>
      </#if>
    </#list>
    </tr>
  </#list>
</body>

2 个答案:

答案 0 :(得分:1)

我已经解决了更改我的代码的以下部分的问题:

{'INFO_FORMAT': 'text/html'}{'INFO_FORMAT': 'application/json'}

现在,网址代表JSON而非HTML

因此,检查和使用数据肯定更容易。

答案 1 :(得分:0)

.find().contents()

一起使用
  

获取当前匹配组中每个元素的后代   元素,由选择器,jQuery对象或元素过滤。

element = $("#info").find("#iframe_id").contents()