Here is my code, and this code to open new tab and focus on it.
Quick test: http://jsfiddle.net/u2jd2oLw/1/
Javascript Code
var tabs = [];
$('#btnOpenTab').on('click', function(){
openTab('http://google.com.vn', 'GG');
});
function openTab(url, tabNm) {
try {
if (tabs[tabNm]) {
tabs[tabNm].focus();
} else {
var mTab = window.open(url, tabNm);
tabs[tabNm] = mTab;
tabs[tabNm].focus();
}
} catch(e) {
alert(e.message);
}
}
HTML Code
<button id="btnOpenTab">Open Tab</button>
Actually, I check in IE11, it occurred that " Access is denied "
And I tried to turn off option: "Turn on Pop-up Blocker" by un-check CheckBox.
Do you have any suggestion?
Thanks!!
It's a security feature in Windows: http://support.microsoft.com/kb/979954
Here are a couple of work arounds to try:
This will work once due to the security issues
$(function() {
$('#btnOpenTab').on('click', function(){
openTab('http://google.com.vn', 'GG');
});
});
function openTab(url, tabNm) {
var mTab = window.open("", tabNm);
mTab.document.write('<body onload="window.focus(); location.replace(\''+url+'\')">Please wait...</body>');
mTab.document.close();
}
It failed to run twice because once the page loads it is no longer same origin.
I tried with an iFrame, but Google blocks that too now
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.