开发者

How to intercept a URL with JQuery

开发者 https://www.devze.com 2023-03-16 09:31 出处:网络
I am currently importing a third party HTML file into my page and it has following java script method tied to a form submit.

I am currently importing a third party HTML file into my page and it has following java script method tied to a form submit.

function ValidateInput(){
       //some code
        if(validationFailed){       
               alert("Validation failed");
                return false;
            }else{   
                return open开发者_如何学运维Win("URL");
        }
    }

I don't have control over this code. But I want to intercept the URL that is mentioned in the openWin function and I want to do some validation on that URL before it opens.

Is it possible with JQuery?


You don't need jQuery.

You can replace the function with your own and call the old one if you want.

var oldOpenWin = openWin;
openWin = function(url) {
    // do validation
    // call old one
    oldOpenWin(url);
}


You can overwrite any function like so:

(function(original_openWin) {
  window.openWin = function() {
    // your own code
    alert('Hello world from openWin intercept');

    // execute original openWin function
    original_openWin();
  }
})(openWin);

Example: http://jsfiddle.net/hyadC/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号