11

In Google Chrome's Dev tools there's a simple dropdown to choose which window you want to execute your script in:

enter image description here

Is there an equivalent in Internet Explorer? I'm trying to run scripts from the console as if they're from an iframe, not the toplevel window.

Tom Lianza
  • 4,012
  • 4
  • 41
  • 50
  • 1
    He's asking for a convenience feature in IE.. Hahahaha. Sorry... Had another 4 hour "Damn-IE-is-not-working-while-every-other-browser-is" session today... – nfechner Mar 04 '12 at 19:33

4 Answers4

14

It is possible, however it’s significantly less convenient than in Chrome.

If you’re able to get a reference to the frame or its window object (using, e.g.: document.getElementById(xxx).contentWindow), you can use the console’s special cd function. This is documented here: http://msdn.microsoft.com/en-us/library/ie/gg589530(v=vs.85).aspx#UsingCDacrossFrames

Annoyingly, this means that if you want to get a reference to a nested iframe, you have to do this inside each each of the parents of the frame that you’re interested in. Debugging in IE is, erm, fun.

Ben Hodgson
  • 500
  • 3
  • 10
  • Note that this only works in IE 9 or greater. There doesn't appear to be a way to do this in IE 8 unfortunately. – nerdherd Mar 28 '14 at 14:44
8

To follow-up on Ben's answer, that would be

cd([reference])

or

cd(frames[n])

where n is a valid index in the window.frames array

Community
  • 1
  • 1
Michael Paulukonis
  • 9,020
  • 5
  • 48
  • 68
2

The feature is now available in IE 11. If you open the dev tools (F12) there's a combo-box in the top right that lets you select the target frame.

Internet Explorer 11 Dev Tools Target Frame combobox

(Note: this is on IE 11.0.9600.17728, not sure if every version of IE 11 has it.)

Mojo Chinto
  • 41
  • 1
  • 8
0

F12 -> script -> choose your page -> console

EDIT:

You can start debug there on java script, add break point and stuff. your keys to run the debugger is like in visual studio.

lolo
  • 17,392
  • 9
  • 25
  • 49
  • The first method doesn't work for me. Ben's `cd` function below is rock-solid, however. – iano Apr 11 '13 at 22:22