Reputation: 6512
I want to open a window in the browser in the following manner:
window.open('/Item/Article/' + result, 'ItemArticle', 'resizable=yes,scrollbars=yes,height=' + res.height + ',width=' + res.width + ',left=0', null);
however if the above dynamic URI does not contain a document no Iframe will be created. Is there a way that I could check whether the item in the URI exists before I attempt to open an iframe, this way I would be able to inform the user that there is no document found.
Upvotes: 1
Views: 72
Reputation: 4984
Let the window open, then use a 404 page for letting the user know that no document was found.
If you really want to do it another way – do an AJAX request like @Raymond suggests, then if you get a successful response, open the window. I can't recommend this however, it means the client will be doing at least one more or less useless request.
Upvotes: 0
Reputation: 48
You can check if the document exists by performing an AJAX request. If it succeeds, you know the URL is valid.
http://api.jquery.com/jQuery.ajax/
var docURL = '/Item/Article/' + result;
$.ajax({
type: 'HEAD',
url: docURL,
success: function () {
window.open('..');
}
});
Upvotes: 1