how to close a new tab that has opened by clicking an image in javascript?
i have written a code in html that will open a link in new tab after clicking an image , but the problem is i am unable to close that new window .
I want to know that how to close that new window??
<html>
<h1>Click on the image below to open google homepage </h1>
<head>
<script>
var x;
var win = document.links;
function closeFunc() {
win[0].close();
}
</script>
</head>
<body>
<a id="google" href="http://www.google.com" target="_blank">
<img src="https://usercontent1.hubstatic.com/12498898_f520.jpg" alt="image" />
</a>
<br> <br>
<button onclick="closeFunc()"> Close</button>
</body>
</html>
javascript html5
|
show 3 more comments
i have written a code in html that will open a link in new tab after clicking an image , but the problem is i am unable to close that new window .
I want to know that how to close that new window??
<html>
<h1>Click on the image below to open google homepage </h1>
<head>
<script>
var x;
var win = document.links;
function closeFunc() {
win[0].close();
}
</script>
</head>
<body>
<a id="google" href="http://www.google.com" target="_blank">
<img src="https://usercontent1.hubstatic.com/12498898_f520.jpg" alt="image" />
</a>
<br> <br>
<button onclick="closeFunc()"> Close</button>
</body>
</html>
javascript html5
2
You can only close windows that were opened withwindow.open()
.
– Barmar
Nov 22 '18 at 6:32
You can't close windows that were opened by clicking on links.
– Barmar
Nov 22 '18 at 6:32
is there any alternative way to close a new window without using open/close()??
– DEBASIS PANDA
Nov 22 '18 at 6:33
No, just use Javascript to handle the click event on the image rather than a hyperlink. In that handler, call window.open() to go to the URL you want.
– Paul
Nov 22 '18 at 6:37
window.open("", "myWindow", "width=200,height=100"); set name ,every time opne windos is same window
– Mars.Tsai
Nov 22 '18 at 6:39
|
show 3 more comments
i have written a code in html that will open a link in new tab after clicking an image , but the problem is i am unable to close that new window .
I want to know that how to close that new window??
<html>
<h1>Click on the image below to open google homepage </h1>
<head>
<script>
var x;
var win = document.links;
function closeFunc() {
win[0].close();
}
</script>
</head>
<body>
<a id="google" href="http://www.google.com" target="_blank">
<img src="https://usercontent1.hubstatic.com/12498898_f520.jpg" alt="image" />
</a>
<br> <br>
<button onclick="closeFunc()"> Close</button>
</body>
</html>
javascript html5
i have written a code in html that will open a link in new tab after clicking an image , but the problem is i am unable to close that new window .
I want to know that how to close that new window??
<html>
<h1>Click on the image below to open google homepage </h1>
<head>
<script>
var x;
var win = document.links;
function closeFunc() {
win[0].close();
}
</script>
</head>
<body>
<a id="google" href="http://www.google.com" target="_blank">
<img src="https://usercontent1.hubstatic.com/12498898_f520.jpg" alt="image" />
</a>
<br> <br>
<button onclick="closeFunc()"> Close</button>
</body>
</html>
javascript html5
javascript html5
edited Nov 22 '18 at 6:45


Krupesh Kotecha
2,06811134
2,06811134
asked Nov 22 '18 at 6:30


DEBASIS PANDADEBASIS PANDA
126
126
2
You can only close windows that were opened withwindow.open()
.
– Barmar
Nov 22 '18 at 6:32
You can't close windows that were opened by clicking on links.
– Barmar
Nov 22 '18 at 6:32
is there any alternative way to close a new window without using open/close()??
– DEBASIS PANDA
Nov 22 '18 at 6:33
No, just use Javascript to handle the click event on the image rather than a hyperlink. In that handler, call window.open() to go to the URL you want.
– Paul
Nov 22 '18 at 6:37
window.open("", "myWindow", "width=200,height=100"); set name ,every time opne windos is same window
– Mars.Tsai
Nov 22 '18 at 6:39
|
show 3 more comments
2
You can only close windows that were opened withwindow.open()
.
– Barmar
Nov 22 '18 at 6:32
You can't close windows that were opened by clicking on links.
– Barmar
Nov 22 '18 at 6:32
is there any alternative way to close a new window without using open/close()??
– DEBASIS PANDA
Nov 22 '18 at 6:33
No, just use Javascript to handle the click event on the image rather than a hyperlink. In that handler, call window.open() to go to the URL you want.
– Paul
Nov 22 '18 at 6:37
window.open("", "myWindow", "width=200,height=100"); set name ,every time opne windos is same window
– Mars.Tsai
Nov 22 '18 at 6:39
2
2
You can only close windows that were opened with
window.open()
.– Barmar
Nov 22 '18 at 6:32
You can only close windows that were opened with
window.open()
.– Barmar
Nov 22 '18 at 6:32
You can't close windows that were opened by clicking on links.
– Barmar
Nov 22 '18 at 6:32
You can't close windows that were opened by clicking on links.
– Barmar
Nov 22 '18 at 6:32
is there any alternative way to close a new window without using open/close()??
– DEBASIS PANDA
Nov 22 '18 at 6:33
is there any alternative way to close a new window without using open/close()??
– DEBASIS PANDA
Nov 22 '18 at 6:33
No, just use Javascript to handle the click event on the image rather than a hyperlink. In that handler, call window.open() to go to the URL you want.
– Paul
Nov 22 '18 at 6:37
No, just use Javascript to handle the click event on the image rather than a hyperlink. In that handler, call window.open() to go to the URL you want.
– Paul
Nov 22 '18 at 6:37
window.open("", "myWindow", "width=200,height=100"); set name ,every time opne windos is same window
– Mars.Tsai
Nov 22 '18 at 6:39
window.open("", "myWindow", "width=200,height=100"); set name ,every time opne windos is same window
– Mars.Tsai
Nov 22 '18 at 6:39
|
show 3 more comments
1 Answer
1
active
oldest
votes
Just Try This
<html>
<h1>Click on the image below to open google homepage </h1>
<head>
<script>
var x;
var win = document.links;
function closeFunc() {
win[0].close();
}
function popuponclick()
{
my_window = window.open("http://www.google.com",
"mywindow");
}
function closepopup()
{
if(false == my_window.closed)
{
my_window.close ();
}
else
{
alert('Window already closed!');
}
}
</script>
</head>
<body>
<a id="google" href="javascript: popuponclick()" target="_blank">
<img src="https://usercontent1.hubstatic.com/12498898_f520.jpg" alt="image" />
</a>
<br> <br>
<button onclick="javascript: closepopup()"> Close</button>
</body>
</html>
hey what's the difference between javascript:pop() and POP() only??
– DEBASIS PANDA
Nov 22 '18 at 7:35
If you want to call function from href property of <a> then you have to use ` javascript:pop() ` otherwise you simply usePOP()
in onclick property.
– Mahesh Rajput
Nov 22 '18 at 7:41
so, only for href, we should use javascript: ??
– DEBASIS PANDA
Nov 22 '18 at 7:47
Yes, for href we use. No need of Thanks just help others.
– Mahesh Rajput
Nov 22 '18 at 7:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425068%2fhow-to-close-a-new-tab-that-has-opened-by-clicking-an-image-in-javascript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just Try This
<html>
<h1>Click on the image below to open google homepage </h1>
<head>
<script>
var x;
var win = document.links;
function closeFunc() {
win[0].close();
}
function popuponclick()
{
my_window = window.open("http://www.google.com",
"mywindow");
}
function closepopup()
{
if(false == my_window.closed)
{
my_window.close ();
}
else
{
alert('Window already closed!');
}
}
</script>
</head>
<body>
<a id="google" href="javascript: popuponclick()" target="_blank">
<img src="https://usercontent1.hubstatic.com/12498898_f520.jpg" alt="image" />
</a>
<br> <br>
<button onclick="javascript: closepopup()"> Close</button>
</body>
</html>
hey what's the difference between javascript:pop() and POP() only??
– DEBASIS PANDA
Nov 22 '18 at 7:35
If you want to call function from href property of <a> then you have to use ` javascript:pop() ` otherwise you simply usePOP()
in onclick property.
– Mahesh Rajput
Nov 22 '18 at 7:41
so, only for href, we should use javascript: ??
– DEBASIS PANDA
Nov 22 '18 at 7:47
Yes, for href we use. No need of Thanks just help others.
– Mahesh Rajput
Nov 22 '18 at 7:51
add a comment |
Just Try This
<html>
<h1>Click on the image below to open google homepage </h1>
<head>
<script>
var x;
var win = document.links;
function closeFunc() {
win[0].close();
}
function popuponclick()
{
my_window = window.open("http://www.google.com",
"mywindow");
}
function closepopup()
{
if(false == my_window.closed)
{
my_window.close ();
}
else
{
alert('Window already closed!');
}
}
</script>
</head>
<body>
<a id="google" href="javascript: popuponclick()" target="_blank">
<img src="https://usercontent1.hubstatic.com/12498898_f520.jpg" alt="image" />
</a>
<br> <br>
<button onclick="javascript: closepopup()"> Close</button>
</body>
</html>
hey what's the difference between javascript:pop() and POP() only??
– DEBASIS PANDA
Nov 22 '18 at 7:35
If you want to call function from href property of <a> then you have to use ` javascript:pop() ` otherwise you simply usePOP()
in onclick property.
– Mahesh Rajput
Nov 22 '18 at 7:41
so, only for href, we should use javascript: ??
– DEBASIS PANDA
Nov 22 '18 at 7:47
Yes, for href we use. No need of Thanks just help others.
– Mahesh Rajput
Nov 22 '18 at 7:51
add a comment |
Just Try This
<html>
<h1>Click on the image below to open google homepage </h1>
<head>
<script>
var x;
var win = document.links;
function closeFunc() {
win[0].close();
}
function popuponclick()
{
my_window = window.open("http://www.google.com",
"mywindow");
}
function closepopup()
{
if(false == my_window.closed)
{
my_window.close ();
}
else
{
alert('Window already closed!');
}
}
</script>
</head>
<body>
<a id="google" href="javascript: popuponclick()" target="_blank">
<img src="https://usercontent1.hubstatic.com/12498898_f520.jpg" alt="image" />
</a>
<br> <br>
<button onclick="javascript: closepopup()"> Close</button>
</body>
</html>
Just Try This
<html>
<h1>Click on the image below to open google homepage </h1>
<head>
<script>
var x;
var win = document.links;
function closeFunc() {
win[0].close();
}
function popuponclick()
{
my_window = window.open("http://www.google.com",
"mywindow");
}
function closepopup()
{
if(false == my_window.closed)
{
my_window.close ();
}
else
{
alert('Window already closed!');
}
}
</script>
</head>
<body>
<a id="google" href="javascript: popuponclick()" target="_blank">
<img src="https://usercontent1.hubstatic.com/12498898_f520.jpg" alt="image" />
</a>
<br> <br>
<button onclick="javascript: closepopup()"> Close</button>
</body>
</html>
answered Nov 22 '18 at 7:28


Mahesh RajputMahesh Rajput
2959
2959
hey what's the difference between javascript:pop() and POP() only??
– DEBASIS PANDA
Nov 22 '18 at 7:35
If you want to call function from href property of <a> then you have to use ` javascript:pop() ` otherwise you simply usePOP()
in onclick property.
– Mahesh Rajput
Nov 22 '18 at 7:41
so, only for href, we should use javascript: ??
– DEBASIS PANDA
Nov 22 '18 at 7:47
Yes, for href we use. No need of Thanks just help others.
– Mahesh Rajput
Nov 22 '18 at 7:51
add a comment |
hey what's the difference between javascript:pop() and POP() only??
– DEBASIS PANDA
Nov 22 '18 at 7:35
If you want to call function from href property of <a> then you have to use ` javascript:pop() ` otherwise you simply usePOP()
in onclick property.
– Mahesh Rajput
Nov 22 '18 at 7:41
so, only for href, we should use javascript: ??
– DEBASIS PANDA
Nov 22 '18 at 7:47
Yes, for href we use. No need of Thanks just help others.
– Mahesh Rajput
Nov 22 '18 at 7:51
hey what's the difference between javascript:pop() and POP() only??
– DEBASIS PANDA
Nov 22 '18 at 7:35
hey what's the difference between javascript:pop() and POP() only??
– DEBASIS PANDA
Nov 22 '18 at 7:35
If you want to call function from href property of <a> then you have to use ` javascript:pop() ` otherwise you simply use
POP()
in onclick property.– Mahesh Rajput
Nov 22 '18 at 7:41
If you want to call function from href property of <a> then you have to use ` javascript:pop() ` otherwise you simply use
POP()
in onclick property.– Mahesh Rajput
Nov 22 '18 at 7:41
so, only for href, we should use javascript: ??
– DEBASIS PANDA
Nov 22 '18 at 7:47
so, only for href, we should use javascript: ??
– DEBASIS PANDA
Nov 22 '18 at 7:47
Yes, for href we use. No need of Thanks just help others.
– Mahesh Rajput
Nov 22 '18 at 7:51
Yes, for href we use. No need of Thanks just help others.
– Mahesh Rajput
Nov 22 '18 at 7:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425068%2fhow-to-close-a-new-tab-that-has-opened-by-clicking-an-image-in-javascript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
You can only close windows that were opened with
window.open()
.– Barmar
Nov 22 '18 at 6:32
You can't close windows that were opened by clicking on links.
– Barmar
Nov 22 '18 at 6:32
is there any alternative way to close a new window without using open/close()??
– DEBASIS PANDA
Nov 22 '18 at 6:33
No, just use Javascript to handle the click event on the image rather than a hyperlink. In that handler, call window.open() to go to the URL you want.
– Paul
Nov 22 '18 at 6:37
window.open("", "myWindow", "width=200,height=100"); set name ,every time opne windos is same window
– Mars.Tsai
Nov 22 '18 at 6:39