How can I open a link (any link) within a certain DOM object in the current page, that is, display the link target's content inside that very DOM element. I would like to do something that would be achieved using an <iframe>
element if it were in the old days, but since <iframe>
is going to be obsolete, I want do it without it.
-
2Are you talking about a link that is to load _your_ content into a certain element? If so you can certainly set that up with ajax. If you are talking about doing it for _any_ link, i.e., links to other websites, it's not going to work without an iframe (as detailed in x3ro's answer). – nnnnnn Jan 07 '12 at 01:53
-
@nnnnnn I meant any link. Thanks. – sawa Jan 07 '12 at 02:02
1 Answers
If I understand you correctly, you'd like to load a new page inside of an existent DOM object inside your page, for example a <div>
. If so, I would assume that this is simply not possible without using an iframe, because every other way you'd have to add content to your current document, which would not display correctly as it is not valid to nest <html>
tags, and you'd have to execute foreign JavaScript on your own page, and you'd have to replace your own CSS and so on.
Also, at least if you are trying to display a page that does not lie inside your own domain, you wouldn't be able to fetch its content with pure JavaScript because of the same origin policy implemented by most (all?) browser JavaScript engines.
Also, iframes are not really deprecated (anymore? they were only deprecated for the strict
versions of HTML4 and XHTML), as you can read here: Are IFrames (HTML) obsolete? They're back in HTML5 :)
-
Thanks. It is a good news to hear that iframe is okay. I will try with it. I had no idea why such an important thing as iframe had been depreceated. But now, things seems okay. – sawa Jan 07 '12 at 02:04