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

http - Javascript, how redirect the main page if you use window.open? - Stack Overflow

programmeradmin2浏览0评论

So I want open a new window/tab and use

<script>
    function popunder() {
        window.open("", '_blank', 'toolbar=yes, location=yes, status=yes, menubar=yes, scrollbars=yes').blur();
    }
</script>

and it works, but I want forward the main page to a new website link at the same time when "window.open" open...

I use onclick="popunder()" too.

I have tried

window.location.href and window.location.replace but it doesn't work.

Also I have no experience of code at all.

How can I forward the main page to another link with the same click which calls window.open?

So I want open a new window/tab and use

<script>
    function popunder() {
        window.open("https://link.here", '_blank', 'toolbar=yes, location=yes, status=yes, menubar=yes, scrollbars=yes').blur();
    }
</script>

and it works, but I want forward the main page to a new website link at the same time when "window.open" open...

I use onclick="popunder()" too.

I have tried

window.location.href and window.location.replace but it doesn't work.

Also I have no experience of code at all.

How can I forward the main page to another link with the same click which calls window.open?

Share Improve this question asked Nov 23, 2018 at 18:42 apriestkoseapriestkose 11 gold badge1 silver badge1 bronze badge 2
  • 1 basically the same code, but remove '_blank' and replace with '_self' – zfrisch Commented Nov 23, 2018 at 18:43
  • Did you try doing this on a regular <a> link? – charlietfl Commented Nov 23, 2018 at 18:47
Add a ment  | 

1 Answer 1

Reset to default 2

If you'd like to use window.open the magic lies in the second parameter (the window name that should be affected) You can read more here : https://developer.mozilla/en-US/docs/Web/API/Window/open

window.open("http://google.", "_blank");
// the above opens a new window/tab

window.open("http://bing.", "_self");
// the above navigates to a new page.

Note on StackOverflow the google popup won't register because it's ing from within the sandbox. You can see a demonstrable version of the above code in this fiddle (be sure not to have your popup blocker on)

发布评论

评论列表(0)

  1. 暂无评论