最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

firefox - How to write and run scripts in the Google Chrome Javascript Console? - Stack Overflow

programmeradmin3浏览0评论

I recently switched from Firefox to Chrome and I (probably) missed an important feature. I was used to test javascript snippets on FF from within the Firebug console this way: open the console, write the script and finally press CTRL + Return to execute the code.

It seems not possible to do the same in Chrome console, as when I type some code there and press return to start a new line the code is executed immediatly.

Is there a way to replicate the Firefox behavior on Chrome?

Thanks.

I recently switched from Firefox to Chrome and I (probably) missed an important feature. I was used to test javascript snippets on FF from within the Firebug console this way: open the console, write the script and finally press CTRL + Return to execute the code.

It seems not possible to do the same in Chrome console, as when I type some code there and press return to start a new line the code is executed immediatly.

Is there a way to replicate the Firefox behavior on Chrome?

Thanks.

Share Improve this question asked Apr 2, 2011 at 18:09 PaoloPaolo 21.1k21 gold badges76 silver badges121 bronze badges
Add a comment  | 

5 Answers 5

Reset to default 4

It seems that there is no explicit “multiline mode”. But you can:

  • Paste code (it will preserve multiline)
  • Shift + Return to add a new line without executing the script

Related bugs:
https://bugs.webkit.org/show_bug.cgi?id=30553
http://code.google.com/p/chromium/issues/detail?id=72739

You can also hit Shift + Enter to start a new line without running the code in Chrome's console: https://developers.google.com/chrome-developer-tools/docs/tips-and-tricks#multiline-commands

Better way of doing this using Chrome featue i.e Snippets where you can write javascript and save it in chrome developer console. Its available underneath source inside developers tools while inspecting element. More info about the snippets can be find on this link.

It was available in Chrome canary and I guess now it is available in default chrome browser also.

Install Firebug Lite for Google Chrome. It has got a console.
Don't look for a full fledged Firebug. You will be disappointed :)

Oops,I didn't read properly at first. My bad!

In Firebug Lite, take Console. Then you will see a tiny red up-arrow at the right corner.
Click on it and you will get a multi-line console. Won't you?

I recommend this:

  1. Write debugger; and hit Enter, in the console tab
  2. This takes you to the Sources tab; if not, make sure debugger breakpoints are active
  3. Now you can write whatever you want in the Sources tab, which acts like a full IDE with features like newline and indentation
  4. Select any part of your code to run, and right-click, choose Evaluate in console
发布评论

评论列表(0)

  1. 暂无评论