Reputation: 18941
I am wanting to embed an HTML fragment (a Google Maps div) using an iframe. (It has to be an iframe, because that is the requirement of the WordPress plugin we are using.)
Embedding the entire HTML of the map page is making the google map misbehave. So is it possible (and good practice) to embed a 'page' that is not a complete HTML page - i.e., a 'page' that is just an HTML snippet (in this case, the map div and associate JavaScript)?
Upvotes: 1
Views: 1178
Reputation: 201866
Whatever you embed with iframe
will be taken as a complete document. Technically, HTML code that consists of only a div
element and a script
element is not valid, but browsers don’t care: they treat it as if it were a complete HTML document containing those elements in its body
.
This answers the question asked, but I presume that you wanted to ask how to extract such elements from a document (dynamically). The answer is that it you would need server-side code that gets a document by URL, parses it, and returns the extracted part. The URL of such a code would then be used in the src
attribute of iframe
. Generally, such operations may constitute a copyright infringement, if performed without the consent of copyright owner. When using Google Maps for example, you should limit your actions to those permitted by Google.
Upvotes: 0
Reputation: 8386
An idea is to set the iframe to the appropriate width and height and set the scrolling attribute to "no". I've seen this many times.
Upvotes: 1