JavaScript Super Bullet window browsing can't stop JS window code

Source: Internet
Author: User

This is really the final mystery of the play window Oh, poof ~, previously wrote an "Ultimate bullet window solution, the human can no longer stop the window!" ", the ultimate version incredibly still have loopholes, helpless can only find another way, even the topic does not know how to draw up, had to write a" man can no longer stop the window! "Did you make it, I'm not here to sell Meng, okay?" o=

Original intention: The company needs, the point of payment, pop up a payment is the success of the prompt box, and open a Third-party payment page in a new window, this interaction believe that even if not done, on the internet also see a lot of.

There are two ways, the basic idea is to generate a form, or generate a A, and then point to a URL for each other, and target for _blank,ok everything is happy, so that the browser can not even play the window recognized.

In fact, there is a simpler way, did not expect the browser such a good trick, such as the following code, the jquery point to the element trigger click event, by returning a false block event:

The code is as follows Copy Code


$ ("#first"). Click (function () {
window.open ("Http://www.111cn.net");
return false;
});

So it's over? In fact, for example, to short Ajax, you see what will happen:

  code is as follows copy code
$ ("#first"). Click (function () {
    $.ajax ({
        type: ' POST ',
        URL: '/deposit/paypoints ',
         Success:function (re) {
            window.open (" Http://www.111cn.net ");
            return false;
       }
   });
});

Find out if the browser found you were going to play the window? God horse situation? Didn't it return false?

Yes, it does return false, but here is a "closure function" where the object of the returned false value is under the scope of the Ajax success, not the event object, of course it's useless.

In addition, I have seen a wonderful version, as for why the wonderful, everyone analysis, here do not speak clearly

The code is as follows Copy Code
$ ("#first"). Click (function () {
$.ajax ({
Type: ' POST ',
URL: '/deposit/paypoints ',
Success:function (re) {
Do sthing ....
}
});

window.open ("Http://www.111cn.net");
return false;
});

So how do you deal with Ajax king?
The window to solve the final mystery!!

Here I first point to the window as an object, and then the object to operate, such as the change of the window to the URL of God horse, it does not sound very puzzling. First code:

The code is as follows Copy Code


$ ("#first"). Click (function () {
var w = window.open (), url, num = 0;
$.ajax ({
Type: ' POST ',
URL: '/deposit/paypoints ',
Success:function (re) {
url = re.url;
},
Error:function () {
W.close ();
num = 20;
}
});

var utime = setinterval (function () {
if (URL) {
W.location = Uurl;
Clearinterval (Utime);
else if (num > 20) {
W.close ();
Clearinterval (Utime);
}

unum++;
}, 200);
});

Let me analyze it again:

First resume a Window object, I open him first
Create an empty URL object and wait for the URL to be received
Create a num, here you can call him a failed counter
All right, Ajax, he's running, asynchronous, and he's only doing two things:
Correct response, assignment URL
Fail Close window, set failed counter to peak
Create a 0.2-second repetitive trigger timer and do two actions:
Get the URL correctly, tell the Window object URL is God Horse
Failed counter peaked, close window

Speaking of which, I don't know if you have a concept, uh, no ... Okay, let me just take a simple example of a friend who's interested.

Example

The code is as follows Copy Code

<a href= "javascript:void (0);" id= "a" > New window opens directly: Stew-study web</a><br/><br,/>
<a href= "javascript:void (0);" id= "Second" > Wait 1 seconds, new window open: Stew-Research Web (poof ~, may be found by the browser Oh = =| | ) </a><br/><br/>
<a href= "javascript:void (0);" id= "Last" > New window opens first, 1 seconds to get URL: stew-research web</a>
<br/><br/>
<a href= "javascript:void (0);" id= "last2" > New window open, 1 seconds to close </a>


$ ("#first"). Click (function () {

window.open ("Http://111cn.net");
return false;
});

$ ("#second"). Click (function () {

settimeout (function () {
window.open ("Http://111cn.net");
}, 1000);

return false;
});

$ ("#last"). Click (function () {
    var w=window.open ();
    settimeout ( function () {
        w.location= "http://111cn.net";
   } , 1000);
   
    return false;
});
$ ("#last2"). Click (function () {
    var w=window.open ();
    settimeout ( function () {
        w.close ();
   }, 1000);
    
    return false;
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.