Aaron Gibralter
Aaron Gibralter

Reputation: 4853

Change the context of the Safari 6 console to an iframe on the page

I know that Chrome let's you pick the context for the console's execution with a dropdown menu and that Firebug let's you cd() into an iframe. I can't figure out how to change the context in Safari's console. Does anyone know how to do this?

Upvotes: 9

Views: 5925

Answers (3)

Mahn
Mahn

Reputation: 16603

As of the time of this writing (July 2024), you can change iframe contexts in Safari via the tiny dropdown button next to the console input in the bottom right corner of the console window:

enter image description here

Upvotes: 0

David Mulder
David Mulder

Reputation: 27030

Safari, unlike chrome and firefox, has no real support for this functionality and the only option seems to be to access the window object from the console. As you correctly point this will trigger cross domain policy issues, however provided you're running on mac (this does not work for some reason on windows) you can use

open -a '/Applications/Safari.app' --args --disable-web-security

to bypass this. And next on your jsbin you could use something along the lines of

window.frames[0]

to access the window of the page. As far as I can see there is no similar solution for windows, as

Safari.exe --disable-web-security

apparantly does not work.

Upvotes: 9

mr.VVoo
mr.VVoo

Reputation: 2270

The Iframe element itself is of Type Window within Console

<iframe id="frame" src="about:blank"/>

In Safari console then you simply work with

frame.document.write('bla');

please notice that 'frame' is shorthand for document.getElementById('frame')

Upvotes: 0

Related Questions