How do I cd into an iframe in chrome developer tools or firebug lite in chrome?

杀马特。学长 韩版系。学妹 提交于 2019-11-29 17:23:22

问题


when I try cd, console says "cd is not defined"


回答1:


Yes, you are right Firebug have this awesome command. I really like it. It's making wotking with iframes much easier. Personally I don't go to Firefox just because the cd() is available in it because I can do whatever I can do with cd in chrome dev tools too.

Just use contentWindow keyword in your command prompt to access the iframe window Object. Then you will be good to access any function and variable out there.

For example I have a variable in my iframe that is not accessible via console normally.

But still I can access to the variable via contentWindow like this:

theIfraem.contentWindow.secret;

If you want to fire a function do this:

theIframe.contentWindow.myfunc();

If you want to define some variables(the hardest one):

var script = document.createElement('scrept');
script.innerHTML = "var secret = 'hi'";
theIframe.contentWindow.document.body.appendChild(script);

This is what cd() actually does. I know it's not as good as Firebugs cd(). But the good news is cd() is coming to Chrome




回答2:


In Chrome Devtools, the "context switcher" is available at the bottom of the page. See the <top frame> dropdown? In there you can change where your script is executing from. This is the same, effectively, as cd().

This is explained more in https://stackoverflow.com/a/8581276/89484



来源:https://stackoverflow.com/questions/5712187/how-do-i-cd-into-an-iframe-in-chrome-developer-tools-or-firebug-lite-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!