Detect if a page is opened in a new tab [duplicate]
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.
javascript jquery asp.net
marked as duplicate by LGSon
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.
add a comment |
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.
javascript jquery asp.net
marked as duplicate by LGSon
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
add a comment |
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.
javascript jquery asp.net
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
javascript jquery asp.net
asked Nov 21 '18 at 18:58
devdev
84
84
marked as duplicate by LGSon
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
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
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
|
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
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
|
show 1 more comment
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
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
|
show 1 more comment
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
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
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
|
show 1 more comment
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
|
show 1 more comment
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