Detect if a page is opened in a new tab [duplicate]












0
















This question already has an answer here:




  • Is it possible to detect if a user has opened a link in a new tab?

    7 answers




I'm implementing a "Go Back" button that redirect the user to the previous page or close the current tab if the page is opened in a new tab.



How can i detect (server side or client side) if the page is opened in a new tab ?



My solution is to pass a parameter (for exemple "new_tab=1") in every href attribute of each <a> tag with target="_blank" so i can read that parameter in the page load event, but i hope in a quicker solution.










share|improve this question













marked as duplicate by LGSon javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 19:05


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • I think you can use this.

    – ya.ymer
    Nov 21 '18 at 19:00













  • Here is working example . : stackblitz.com/edit/angular-kfqdzn

    – programoholic
    Nov 21 '18 at 19:34
















0
















This question already has an answer here:




  • Is it possible to detect if a user has opened a link in a new tab?

    7 answers




I'm implementing a "Go Back" button that redirect the user to the previous page or close the current tab if the page is opened in a new tab.



How can i detect (server side or client side) if the page is opened in a new tab ?



My solution is to pass a parameter (for exemple "new_tab=1") in every href attribute of each <a> tag with target="_blank" so i can read that parameter in the page load event, but i hope in a quicker solution.










share|improve this question













marked as duplicate by LGSon javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 19:05


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • I think you can use this.

    – ya.ymer
    Nov 21 '18 at 19:00













  • Here is working example . : stackblitz.com/edit/angular-kfqdzn

    – programoholic
    Nov 21 '18 at 19:34














0












0








0









This question already has an answer here:




  • Is it possible to detect if a user has opened a link in a new tab?

    7 answers




I'm implementing a "Go Back" button that redirect the user to the previous page or close the current tab if the page is opened in a new tab.



How can i detect (server side or client side) if the page is opened in a new tab ?



My solution is to pass a parameter (for exemple "new_tab=1") in every href attribute of each <a> tag with target="_blank" so i can read that parameter in the page load event, but i hope in a quicker solution.










share|improve this question















This question already has an answer here:




  • Is it possible to detect if a user has opened a link in a new tab?

    7 answers




I'm implementing a "Go Back" button that redirect the user to the previous page or close the current tab if the page is opened in a new tab.



How can i detect (server side or client side) if the page is opened in a new tab ?



My solution is to pass a parameter (for exemple "new_tab=1") in every href attribute of each <a> tag with target="_blank" so i can read that parameter in the page load event, but i hope in a quicker solution.





This question already has an answer here:




  • Is it possible to detect if a user has opened a link in a new tab?

    7 answers








javascript jquery asp.net






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 18:58









devdev

84




84




marked as duplicate by LGSon javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 19:05


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by LGSon javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 19:05


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • I think you can use this.

    – ya.ymer
    Nov 21 '18 at 19:00













  • Here is working example . : stackblitz.com/edit/angular-kfqdzn

    – programoholic
    Nov 21 '18 at 19:34



















  • I think you can use this.

    – ya.ymer
    Nov 21 '18 at 19:00













  • Here is working example . : stackblitz.com/edit/angular-kfqdzn

    – programoholic
    Nov 21 '18 at 19:34

















I think you can use this.

– ya.ymer
Nov 21 '18 at 19:00







I think you can use this.

– ya.ymer
Nov 21 '18 at 19:00















Here is working example . : stackblitz.com/edit/angular-kfqdzn

– programoholic
Nov 21 '18 at 19:34





Here is working example . : stackblitz.com/edit/angular-kfqdzn

– programoholic
Nov 21 '18 at 19:34












1 Answer
1






active

oldest

votes


















-1














You can look at the history.length property to see the length of pages in the stack, with history.length === 1 meaning a new tab.



https://developer.mozilla.org/en-US/docs/Web/API/History






share|improve this answer



















  • 1





    I don't see how this would indicate if the client has opened the new page in a new tab. What if once the new tab is opened, the user navigates?

    – Scott Marcus
    Nov 21 '18 at 19:04











  • Well once the user navigates, the tab wouldn't be considered a new tab and therefore the OP's Go Back button should work.

    – dotconnor
    Nov 21 '18 at 19:08











  • OP says that clicking back in a window that was opened in a new tab should close the window. So, if a new tab opens and the user navigates and then clicks back, the window should close. In your case, they would just go back to the previous page.

    – Scott Marcus
    Nov 21 '18 at 19:10











  • The way I read the OP's question is if there is no page to go back to, then the tab should close. I'm sorry if that's not the way you read it.

    – dotconnor
    Nov 21 '18 at 19:11













  • or close the current tab if the page is opened in a new tab

    – Scott Marcus
    Nov 21 '18 at 19:12


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









-1














You can look at the history.length property to see the length of pages in the stack, with history.length === 1 meaning a new tab.



https://developer.mozilla.org/en-US/docs/Web/API/History






share|improve this answer



















  • 1





    I don't see how this would indicate if the client has opened the new page in a new tab. What if once the new tab is opened, the user navigates?

    – Scott Marcus
    Nov 21 '18 at 19:04











  • Well once the user navigates, the tab wouldn't be considered a new tab and therefore the OP's Go Back button should work.

    – dotconnor
    Nov 21 '18 at 19:08











  • OP says that clicking back in a window that was opened in a new tab should close the window. So, if a new tab opens and the user navigates and then clicks back, the window should close. In your case, they would just go back to the previous page.

    – Scott Marcus
    Nov 21 '18 at 19:10











  • The way I read the OP's question is if there is no page to go back to, then the tab should close. I'm sorry if that's not the way you read it.

    – dotconnor
    Nov 21 '18 at 19:11













  • or close the current tab if the page is opened in a new tab

    – Scott Marcus
    Nov 21 '18 at 19:12
















-1














You can look at the history.length property to see the length of pages in the stack, with history.length === 1 meaning a new tab.



https://developer.mozilla.org/en-US/docs/Web/API/History






share|improve this answer



















  • 1





    I don't see how this would indicate if the client has opened the new page in a new tab. What if once the new tab is opened, the user navigates?

    – Scott Marcus
    Nov 21 '18 at 19:04











  • Well once the user navigates, the tab wouldn't be considered a new tab and therefore the OP's Go Back button should work.

    – dotconnor
    Nov 21 '18 at 19:08











  • OP says that clicking back in a window that was opened in a new tab should close the window. So, if a new tab opens and the user navigates and then clicks back, the window should close. In your case, they would just go back to the previous page.

    – Scott Marcus
    Nov 21 '18 at 19:10











  • The way I read the OP's question is if there is no page to go back to, then the tab should close. I'm sorry if that's not the way you read it.

    – dotconnor
    Nov 21 '18 at 19:11













  • or close the current tab if the page is opened in a new tab

    – Scott Marcus
    Nov 21 '18 at 19:12














-1












-1








-1







You can look at the history.length property to see the length of pages in the stack, with history.length === 1 meaning a new tab.



https://developer.mozilla.org/en-US/docs/Web/API/History






share|improve this answer













You can look at the history.length property to see the length of pages in the stack, with history.length === 1 meaning a new tab.



https://developer.mozilla.org/en-US/docs/Web/API/History







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 19:00









dotconnordotconnor

1,072220




1,072220








  • 1





    I don't see how this would indicate if the client has opened the new page in a new tab. What if once the new tab is opened, the user navigates?

    – Scott Marcus
    Nov 21 '18 at 19:04











  • Well once the user navigates, the tab wouldn't be considered a new tab and therefore the OP's Go Back button should work.

    – dotconnor
    Nov 21 '18 at 19:08











  • OP says that clicking back in a window that was opened in a new tab should close the window. So, if a new tab opens and the user navigates and then clicks back, the window should close. In your case, they would just go back to the previous page.

    – Scott Marcus
    Nov 21 '18 at 19:10











  • The way I read the OP's question is if there is no page to go back to, then the tab should close. I'm sorry if that's not the way you read it.

    – dotconnor
    Nov 21 '18 at 19:11













  • or close the current tab if the page is opened in a new tab

    – Scott Marcus
    Nov 21 '18 at 19:12














  • 1





    I don't see how this would indicate if the client has opened the new page in a new tab. What if once the new tab is opened, the user navigates?

    – Scott Marcus
    Nov 21 '18 at 19:04











  • Well once the user navigates, the tab wouldn't be considered a new tab and therefore the OP's Go Back button should work.

    – dotconnor
    Nov 21 '18 at 19:08











  • OP says that clicking back in a window that was opened in a new tab should close the window. So, if a new tab opens and the user navigates and then clicks back, the window should close. In your case, they would just go back to the previous page.

    – Scott Marcus
    Nov 21 '18 at 19:10











  • The way I read the OP's question is if there is no page to go back to, then the tab should close. I'm sorry if that's not the way you read it.

    – dotconnor
    Nov 21 '18 at 19:11













  • or close the current tab if the page is opened in a new tab

    – Scott Marcus
    Nov 21 '18 at 19:12








1




1





I don't see how this would indicate if the client has opened the new page in a new tab. What if once the new tab is opened, the user navigates?

– Scott Marcus
Nov 21 '18 at 19:04





I don't see how this would indicate if the client has opened the new page in a new tab. What if once the new tab is opened, the user navigates?

– Scott Marcus
Nov 21 '18 at 19:04













Well once the user navigates, the tab wouldn't be considered a new tab and therefore the OP's Go Back button should work.

– dotconnor
Nov 21 '18 at 19:08





Well once the user navigates, the tab wouldn't be considered a new tab and therefore the OP's Go Back button should work.

– dotconnor
Nov 21 '18 at 19:08













OP says that clicking back in a window that was opened in a new tab should close the window. So, if a new tab opens and the user navigates and then clicks back, the window should close. In your case, they would just go back to the previous page.

– Scott Marcus
Nov 21 '18 at 19:10





OP says that clicking back in a window that was opened in a new tab should close the window. So, if a new tab opens and the user navigates and then clicks back, the window should close. In your case, they would just go back to the previous page.

– Scott Marcus
Nov 21 '18 at 19:10













The way I read the OP's question is if there is no page to go back to, then the tab should close. I'm sorry if that's not the way you read it.

– dotconnor
Nov 21 '18 at 19:11







The way I read the OP's question is if there is no page to go back to, then the tab should close. I'm sorry if that's not the way you read it.

– dotconnor
Nov 21 '18 at 19:11















or close the current tab if the page is opened in a new tab

– Scott Marcus
Nov 21 '18 at 19:12





or close the current tab if the page is opened in a new tab

– Scott Marcus
Nov 21 '18 at 19:12





Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

How to fix TextFormField cause rebuild widget in Flutter