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

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

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论