Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to emulate an iframe?

is there a way to get the contents of a page, for example http://google.com, and insert it in the current document, but in the way that the iframe does, I mean... with styles, scripts and everything that page has ?

And make so the styles and scripts don't affect the current document :)

like image 646
Alex Avatar asked Apr 26 '11 09:04

Alex


People also ask

Is it bad practice to use iframe?

Iframes Bring Security Risks. If you create an iframe, your site becomes vulnerable to cross-site attacks. You may get a submittable malicious web form, phishing your users' personal data. A malicious user can run a plug-in.

Are IFrames being phased out?

IFrames are not obsolete, but the reasons for using them are rare. Using IFrames to serve your own content creates a "wall" around accessing the content in that area. For crawlers like Google, It's not immediately clear that cotent in an iframe will be ranked as highly as if the content were simply part of the page.

Can you iframe anything?

iFrames can be used for almost anything, from articles, to website homepages, to learning modules and beyond. As Tech Target explains, “an inline frame (iFrame) is a HTML element that loads another HTML page within the document. It essentially puts another webpage within the parent page.

Is iframe a viewport?

Inside an iframe, the visual viewport is the size of the inner width and height of the iframe, rather than the parent document. You can set any height and width on an iframe, but the whole document may not be visible.


2 Answers

No, not really: you can get the contents of a page through various AJAX-y techniques, but when you insert them into your page, they'll always have your page's CSS applied to them. You could make some sort of "CSS reset" for the "not-iframe" element, but this will be messy.

Essentially, if you want the separation provided by frames, you need to use frames/iframes (unfortunately, this applies to all content, so CSS will be separated, but also JS, with all the related cross-domain brouhaha).

like image 91
Piskvor left the building Avatar answered Sep 25 '22 18:09

Piskvor left the building


Absolutely. You can use the object element, like so:

<!DOCTYPE html>
<html>
    <body>
        <object data="http://www.google.com" type="text/html"></object>
    <body>
</html>

(Works with IE8, Chrome 10, FF 4, and Safari 5 on Win XP)

like image 44
james.garriss Avatar answered Sep 24 '22 18:09

james.garriss