-1
javascript: var conf = confirm("Do you want to close this page?"); if(conf) {window.close()};

Why when i write this code in the url bar (chrome) it doesn't work, but it works through editor. And if i write only "javascript: close()" in the url bar it also works. Is it some of chrome restrictions or what? And the question is not 'how to close a tab', but why code doesn't work in the url bar. Thanks.

Artem Sh
  • 21
  • 1
  • 2

1 Answers1

-3

If you write anything that is not an address into the url bar, it will search for it using your designated search engine.

If you want to run javascript on a page in chrome, open the terminal with command + Opt + j on mac, or command + Ctrl + j on pc Alternatively you can right click anywhere on the page, click "inspect" or "inspect element", and navigate to the console from there.

You do not have to prefix any of your code with "javascript:" in the console, just enter the code directly and press return.

Stiggandr
  • 7
  • 4