Get the App
SLTechnology News&Howtos  ›  Development  › 

What if open is intercepted in window?

Shulou Source: shulou.com Published: 2022-06-03 09:57:31 10月02日 Update

This article mainly introduces how to intercept open in window, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it with you.

In the security mechanism of Chrome, window.open methods that are not directly triggered by users are blocked. This is because browsers forbid the direct use of window.open (url) to open new links in js in order to maintain user security and experience (window.open (url, "_ self") changes the current window can take effect).

The solution to the interception of windowopen

1. The way the form is submitted

Varform=document.createElement ('form')

Form.action='www.baidu.com?id=1'

Form.target='_blank'

Form.method='POST'

Document.body.appendChild (form)

Form.submit ()

In this way, if you need to pass parameters, you need to use the POST method, and the default GET method cannot pass parameters. That is, there are no parameters in the url of the new page.

In addition, Ajax uses form forms to simulate downloads when downloading files.

two。 Put the open window action directly in the button / link onclick event

3. Delay this open operation

SetTimeout ('window.open (url);', 500); / / delay time cannot be too short, otherwise it will also be intercepted.

Windowopen is intercepted and changed mode.

Open a new window through js will be blocked, another way of implementation

Vartempwindow=window.open ('_ blank'); / / Open the page first

Change the page address after temp_window.location=' http://www.baidu.com';//

Thank you for reading this article carefully. I hope the article "what to do if open is blocked in window" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Ways methods articles parameters pages what to do security users forms links delays that is events values interests at the same time addresses buttons files time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Tech Info Linux Docker MySQL