1

I have the following HTML with jQuery code:

<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>');

The string url1 returns an iframe element of a table with elements.

How can I access the elements in the iframe?

I would like to add a condition where if the iframe lacks contents, the whole <div id='info'> can be hidden using jQuery.

The string: url1 contains the following code:

<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>

Eugene Sajine
  • 8,104
  • 3
  • 23
  • 28
Javier Muñoz
  • 732
  • 1
  • 11
  • 30
  • It really depends. If you generate the iframe, you could get it. If the iframe points to other domain or other subdomain of your current site, there is a problem. http://stackoverflow.com/questions/3420004/access-parent-url-from-iframe – Razvan Dumitru Feb 25 '15 at 16:42
  • If you generate the iframe you could write there a script get current url from document href and do your job. – Razvan Dumitru Feb 25 '15 at 16:43

2 Answers2

1

I've solved the problem changing the following part of my code:

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

Now, URL represent an JSON and not HTML.

So, It's definitely more easier to check and use the data.

Javier Muñoz
  • 732
  • 1
  • 11
  • 30
0

Use .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()
Tui Popenoe
  • 2,098
  • 2
  • 23
  • 44