Here is what I’m trying to do:
httpReq.onreadystatechange = function() {
if (httpReq.readyState == 4) {
if (httpReq.status == 200) {
var response = httpReq.responseText;
if (response == "-2") document.shortener_form.urlField.value = "";
else {
document.shortener_form.urlField.value = response;
window.open("http://example.com", '_blank');
}
} else {
document.shortener_form.urlField.value = "Error!";
}
}
};
The window.open function on line 8 is not executing. It works everywhere else, just not within that anonymous function. I’m terrible at Javascript, I’ve searched Google and SO however found no answer. Thanks.
Edit: by the way, the function works everywhere else on the page and script, so I’ve isolated the problem to be within this anonymous function.
It is a popup blocker problem. Your browser doesn’t want to allow
window.open()unless it is the direct result from a user action (e.g. mouse click).