I have tried the following to achieve this:
- Jquery Open in new Tab (_blank)
- How can I open a link in a new window?
But neither works when calling window.open
from inside the callback. Here's my code
$.post('api', {
}, function() {
var win = window.open('target-file', '_blank');
win.focus();
});
I have tried the following to achieve this:
- Jquery Open in new Tab (_blank)
- How can I open a link in a new window?
But neither works when calling window.open
from inside the callback. Here's my code
$.post('api', {
}, function() {
var win = window.open('target-file', '_blank');
win.focus();
});
Share
Improve this question
edited May 23, 2017 at 12:01
CommunityBot
11 silver badge
asked May 10, 2013 at 10:09
coder9coder9
1,5491 gold badge28 silver badges52 bronze badges
2
- 2 The new window may be blocked by a popup-blocker? – mariusnn Commented May 10, 2013 at 10:12
- possible duplicate of Why can't I open a new window on my jquery ajax callback? – Adil Shaikh Commented May 10, 2013 at 10:13
4 Answers
Reset to default 2Try this:
$.post('api', {
}, function() {
window.open('target-file', '_blank');
});
try it with the name of the window
Like
window.open("url", "NameOfNewWindow");
SEE HERE
use MySurfaceWindow = window.open("url","windowname","settings");
see below example:
MySurfaceWindow = window.open('/DesktopModules/DMS/DMS.PatientEChart/Surface Pages/Surface6.aspx?SurfaceTooth=' + $("#lbl" + $(this).val()).text() + '&ProcedureID=0' + '&ColorD=I' + '', '', 'height=240,width=200,top=' + top + ',left=' + left + 'status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no');
ou can add this simple jQuery snipplet to your source to open every external link in a new tab of the web browser
$(document).ready(function(){
$('a').each(function() {
var a = new RegExp('/' + window.location.host + '/');
if(!a.test(this.href)) {
$(this).click(function(event) {
event.preventDefault();
event.stopPropagation();
window.open(this.href, '_blank');
});
}
});
});