Open a new page in the browser's new tab or New window via JavaScript, and the results are blocked by the browser.
The front-end submits the data to the backend, the back end returns the URL, and opens the URL in a new window (how the front-end data request uses the asynchronous request)
Two ways to open a new window in your own use
- window.open ()
- Target= "_blank" with a tag
Insert a tag in the template, and then JavaScript to trigger the click of a link to implement a jump. (This method has a pit in jquery and js ...) ) $ (' a '). Get (0) Pay attention to this piece!!!!
Jquery***<a href= "http://wuliv.com" id= "opennew" ></a>$ (function () { $ (' #openNew '). Click ()})/ /Failure Invalid//***jquery***<a href= "http://wuliv.com" id= "opennew" > <span><span></a>$ ( function () { $ (' #openNew span '). Click ()})//Successfully open a new page//***javascript***<a href= "http://wuliv.com" id= "Opennew" ></a>document.getelementbyid (' Opennew '). Click ()//Open new page successfully
When using jquery to trigger a-tag click Jump, you need to insert a sub-tab in the a tag, and then trigger the Sub-tab click to implement a tab jump (a bit around)
$ ("#openNew") is a jquery object, and jquery itself encapsulates some of the object's properties, which causes the click to fail, while using the JS object document.getElementById ("a") will not have the problem
The onclick () can also trigger an event, but the onclick is different from the click;
The onclick triggers the method, and click Triggers the button's Click event before triggering the method.
If the object does not have a binding onclick method, it cannot be triggered, and the click does not have a binding method to trigger.
The reason for the failure to pop up a new window:
1. Use window.open (), but the window name is defined, that is, the name parameter is passed in the open window, because window.open can only open a window page with a unique window named name, which cannot be opened if the same name exists.
2. Solution: window.open () does not define the window name
3. Use an asynchronous request to request data through Ajax to the server, and then open a new window after the request is completed. Because the asynchronous request has a delay, the browser will not assume that the user triggered the action.
4. Solution:
2.1 How AJAX requests are set to synchronize
2.2 If you use the Ajax method in jquery to make an asynchronous request, you can configure it so that the async: false
request becomes synchronous.
2.2 vue2.0 uses Axios to make data requests, Axios settings that do not have synchronization requests, are asynchronous.
Open a blank new window before Axios request
var newPage = window.open () has a title on the blank page that is open, and it shows "Untitled"
The window.open (' About:blank ') title shows ' About:blank '
Then write the URL to open in Axios's then callback
window.open (' About:blank ')
browser blocker JS open new window