Reputation: 1136
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 openWin("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?
Upvotes: 0
Views: 616
Reputation: 3928
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/
Upvotes: 1
Reputation: 14627
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);
}
Upvotes: 4