I want to open a new tab using JavaScript or jQuery.
I tried this code:
window.open("myurl", '_blank');
But browser gives me alert for pop-up blocked.
I have to open new tab without pop-up blocked alert.
Each and every client can't allow pop-up.
Can anyone help me please?
I want to open a new tab using JavaScript or jQuery.
I tried this code:
window.open("myurl", '_blank');
But browser gives me alert for pop-up blocked.
I have to open new tab without pop-up blocked alert.
Each and every client can't allow pop-up.
Can anyone help me please?
Share Improve this question edited May 27, 2015 at 10:34 Biffen 6,3546 gold badges31 silver badges37 bronze badges asked May 27, 2015 at 10:29 Shrinivas MeseShrinivas Mese 691 gold badge1 silver badge8 bronze badges 4- 1 That's just your browser security. No way around this. ( apart from lowering your security ) – Josh Stevenson Commented May 27, 2015 at 10:32
- 2 Try searching before asking a question please stackoverflow.com/questions/4907843/… – George Commented May 27, 2015 at 10:32
- click on the popup blocker and then just check the always allowed popup from.... option. – Jai Commented May 27, 2015 at 10:34
- @Jai Each and every client can't allow pop-up. so can i achive this without popup blocker. when we are writing some html code like anchor tag with target is blank then it opens new tab without popup blocker. – Shrinivas Mese Commented May 27, 2015 at 10:48
4 Answers
Reset to default 6try this,
$('#myButton').click(function () {
var redirectWindow = window.open('http://google.com', '_blank');
redirectWindow.location;
});
working js fiddle for this http://jsfiddle.net/safeeronline/70kdacL4/2/
working js fiddle for ajax window open http://jsfiddle.net/safeeronline/70kdacL4/1/
The only way to overcome this is to perform a synchronous Ajax request which will block your browser while it runs, but will preserve the event context. This will help---> Open new tab without popup blocker after ajax call on user click
Here is the sample code for you --->
<table>
<tr>
<td>Works without warning in all browsers:</td>
<td><input type="button" onclick="performSyncronousRequest()" value="Syncronous request"/><td>
</tr>
</tr>
</table>
Scipt--->
/**
* This method will give open the popup without a warning.
*/
function performSyncronousRequest() {
$.ajax({
url: '/echo/html',
data: {},
success: function(){
window.open('http://www.w3schools.com');
},
async: false
});
}
Heres the working fiddle http://jsfiddle.net/23JNw/80/
var win = window.open('http://stackoverflow.com/', '_blank');
if(win){
//Browser has allowed it to be opened
win.focus();
}else{
//Broswer has blocked it
alert('Please allow popups for this site');
}
You can try like this
$(document).on('click', '.preview', function(event) {
event.preventDefault();
if (confirm("Are You Sure?"))
{
var daoGroup = $("#daoGroup").val();
if (daoGroup === undefined && daoGroup === null) {
alert("Select DAO Groups");
return false;
}
else
{
/* Act on the event */
var data = $(".frmContent").serialize();
var url = '<?php echo base_url() ?>reportViewPrint/sailorNominalRoll/htmlPreview';
window.open(url+'?'+ data, '_blank');
}
}
});