如何访问 iframe 中 URL 的参数?

How I can access to the parameters of an URL within of an iframe?

我有以下 HTML 和 jQuery 代码:

<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 returns table 的 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>

使用.find() with .contents()

Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.

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

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

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

现在,URL 代表 JSON 而不是 HTML

所以,肯定更容易查看和使用数据。