2

I want to allow any page to be loaded inside an iframe. It's for teaching purposes so I want to know if it's possible to force let's say:

<iframe src="http://www.wolframalpha.com/input/?i=5*sin%28x%29" width="400" height="100">

to stay inside the iframe. By default it has some kind of javascript that opens in full page.

UPDATE: What if i use frames? (please don't throw bricks at me) Could they know if the page is inside a frame?

AlfredoVR
  • 4,069
  • 3
  • 25
  • 33
  • Cannot be done I think (/ I hope). I use such a script myself. `if (window!=top){top.location.href=location.href;}` – PeeHaa Dec 11 '11 at 20:28
  • 3
    [Classic Jeff Atwood question on the topic.](http://stackoverflow.com/questions/958997/frame-buster-buster-buster-code-needed) – Pointy Dec 11 '11 at 20:39
  • Are you sure you're not breaking the WA terms and conditions by trying to do this? It's _their_ website, and they want it _not_ embedded in yours. Seems fair to me. – Lightness Races in Orbit Dec 11 '11 at 20:42

3 Answers3

0

If the page itself wants to break out of being framed with it's own javascript (which apparently this page is doing), it can do so and I know of no way to prevent it other than turning javascript off in your own browser which obviously isn't an option for general viewing.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
0

On some browsers, you can set an attribute on the iframe element that sets a security policy that prevents the iframe from executing JavaScript. I don't remember the attribute name and not sure which browsers support it (I'm sure ie does, not quite sure about the others). If you have problem finding more details, I'll look it up when I get home (on a mobile right now)

edit: found it - security="restricted". Seems to be IE-only.

shesek
  • 4,584
  • 1
  • 28
  • 27
-1

If you have links outside of this iFrame and want them to load into that iFrame on the same page, you'll have to give it a name, then target the named iFrame within your link's href.

<iframe src="http://google.com" name="myframe" hieght="100" width="100"></iframe>
<br />
<a href="http://reddit.com" target="myframe">Derp</a>.

However, if you're loading a page into your iFrame that's loading links with target="blank", then those will go to a new window; unless you don't have access to those pages, you won't be able to change the links (short of writing JS to dive into your iFrame, etc).

RomoCode
  • 1,099
  • 9
  • 17