javascript window.open will not work on Chrome console? - Stack Overflow

I'm trying to test on Chrome console (F12):window.open("www.stackoverflow");But I just g

I'm trying to test on Chrome console (F12):

window.open("www.stackoverflow");

But I just get:

undefined

Shouldn't it work here?

I'm trying to test on Chrome console (F12):

window.open("www.stackoverflow.");

But I just get:

undefined

Shouldn't it work here?

Share Improve this question edited May 13, 2016 at 20:33 Barmar 784k57 gold badges548 silver badges659 bronze badges asked May 13, 2016 at 20:30 StudentStudent 28.4k70 gold badges167 silver badges267 bronze badges 6
  • Is your pop-up blocker blocking it like this? – Rion Williams Commented May 13, 2016 at 20:33
  • That's what happens to me. – Mike Feltman Commented May 13, 2016 at 20:33
  • For me it is working. Try your pop-up blocker, because this is how most spam sites opens new content without your permission. – Leonel Atencio Commented May 13, 2016 at 20:35
  • @RionWilliams yes! just saw it, it shows briefly only on first attempt. Is there a way to bypass it with javascript? – Student Commented May 13, 2016 at 20:35
  • 1 This is likely there for security purposes as the window.open() function generally requires user interaction of some kind in order to open one without being blocked (i.e. clicking a button, etc.) – Rion Williams Commented May 13, 2016 at 20:36
 |  Show 1 more ment

4 Answers 4

Reset to default 2

This is likely a result of security measures taking over to protect the browser. Generally the window.open() function requires some type of user interaction in order to be opened programatically (i.e. a button being clicked, etc.).

If no behavior like this occurs and the browser receives a window.open() request, the built-in pop-up blocker will likely handle it as it will assume something nefarious is afoot.

Try the javascript protocol in the navigation bar.

In Chrome go to location where you type URL and type:

javascript:window.open("www.stackoverflow."); <ENTER>

It works! A new window will open.

Note, if you copy/paste the text I typed, it'll try to protect you by not allowing it.

Note 2: If you change the domain it'll try to protect you from XSS (cross-site scripting).

Your URL is for a file named www.stackoverflow. in the same directory as the current web page. To indicate that it should use that as a server name, the name needs to be prefaced with //.

window.open('//www.stackoverflow.');

Also, if the current page you're viewing is not from an HTTP server, you'll need the protocol scheme as well; otherwise, it will try to use the same protocol.

window.open('http://www.stackoverflow.');

Try:

window.open("http://www.stackoverflow.");

Ps. You are writing "windows" instead of "window".


EDIT

He wrote "windows" in the title and then edited it.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745399233a4626023.html

相关推荐

  • javascript window.open will not work on Chrome console? - Stack Overflow

    I'm trying to test on Chrome console (F12):window.open("www.stackoverflow");But I just g

    8小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信