I would like to know if there is an alternative to iFrames with HTML5. I mean by that, be able able to inject cross-domains HTML inside of a webpage without using an iFrame.
相关问题
- how to get selected text from iframe with javascri
- How do you scroll an iframe from within using jque
- Is there any way to make the background of a 3D-mo
- Iframe scrollbar align to right
- I would like to manipulate the html inside an ifra
相关文章
- iframe的里内容看不到,但却点得到
- HTML5 control
- iframe content disappears on Firefox
- Changing an IFrames InnerHtml from codebehind
- Scrolling issues with ExtJS 5 app inside IFrame
- iframe not reading cookies in Chrome
- Does html5 local storage store per iframe?
- X-Frame-Options ALLOW-FROM a specific site allows
This also does seem to work, although W3C specifies it is not intended "for an external (typically non-HTML) application or interactive content"
More info: http://www.w3.org/wiki/HTML/Elements/embed http://www.w3schools.com/tags/tag_embed.asp
I created a node module to solve this problem node-iframe-replacement. You provide the source URL of the parent site and CSS selector to inject your content into and it merges the two together.
Changes to the parent site are picked up every 5 minutes.
The source contains a working example of injecting content into the BBC News home page.
Basically there are 4 ways to embed HTML into a web page:
<iframe>
An iframe's content lives entirely in a separate context than your page. While that's mostly a great feature and it's the most compatible among browser versions, it creates additional challenges (shrink wrapping the size of the frame to its content is tough, insanely frustrating to script into/out of, nearly impossible to style).XMLHttpRequest
object to retrieve data and inject it to your page. It is not ideal because it depends on scripting techniques, thus making the execution slower and more complex, among other drawbacks.HTML5 Web Components. HTML Imports, part of the Web Components, allows to bundle HTML documents in other HTML documents. That includes
HTML
,CSS
,JavaScript
or anything else an.html
file can contain. This makes it a great solution with many interesting use cases: split an app into bundled components that you can distribute as building blocks, better manage dependencies to avoid redundancy, code organization, etc. Here is a trivial example:Native compatibility is still an issue, but you can use a polyfill to make it work in evergreen browsers Today.
You can learn more here and here.
You can use an XMLHttpRequest to load a page into a div (or any other element of your page really). An exemple function would be:
If your sever is capable, you could also use PHP to do this, but since you're asking for an HTML5 method, this should be all you need.
you can use object tag This also does seem to work
An iframe is still the best way to download cross-domain visual content. With AJAX you can certainly download the HTML from a web page and stick it in a div (as others have mentioned) however the bigger problem is security. With iframes you'll be able to load the cross domain content but won't be able to manipulate it since the content doesn't actually belong to you. On the other hand with AJAX you can certainly manipulate any content you are able to download but the other domain's server needs to be setup in such a way that will allow you to download it to begin with. A lot of times you won't have access to the other domain's configuration and even if you do, unless you do that kind of configuration all the time, it can be a headache. In which case the iframe can be the MUCH easier alternative.
As others have mentioned you can also use the embed tag and the object tag but that's not necessarily more advanced or newer than the iframe.
HTML5 has gone more in the direction of adopting web APIs to get information from cross domains. Usually web APIs just return data though and not HTML.