In web programming, when using JS to open a page in a new window, you will encounter a situation where the browser is intercepted. So, how can we make JS open a new window without being blocked by the browser?
1. Question 1
Generally speaking, if you call the window.open() function directly in js to open a new window, the browser will intercept the pop-up window, because the browser will consider the window to be a form that the user does not want to get.
1. Solution
Change the window.open() function to be triggered when the user actively clicks it, and add the onclick event to the hyperlink. This way the browser thinks that the user wants to access this page, rather than popping it directly to the user.
2. For example:
<a href="javascript:void(0)" onclick="window.open()"></a>
In this way, the user clicks on this hyperlink and the browser will think it is opening a new link, so it will not intercept it.
2. Question 2
Use ajax to process data. When you click to get the data, you will jump to a new page. At this time, you will be intercepted by the browser.
1. Solution
First use window.open to open a window, and then modify the window address
2. For example
var tempwindow=window.open();tempwindow.location='/jump/new';
The above is the solution to the intercepted JS pop-up new window introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!