Is there a way to change context to iframe in javascript console?

后端 未结 6 2119
春和景丽
春和景丽 2020-11-29 20:42

I would like to change the context of the javascript executed in the webkit developer tool/firebug console to execute its code like it is running from inside an iframe on th

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 21:18

    In today's Chrome (version 52), all you have to do is select the iframe in the "Elements" tab of the dev tools. Anything you run in the JS console will automatically run in the context of the selected iframe.

    For example, here I've selected an iframe, and when I type document.location.pathname into the console it returns the src attribute of the iframe, instead of the URL from the address bar:

提交回复
热议问题