I have a button and i need to show an image in a popup when i click this button.
Why this code doesn't work? I try with a window.open in onclick
event but it doesn't work
<input type="button" value="Mostra Immagine" onclick=window.open(src="../img/mypicture.jpg")>
Where is my error?
I have a button and i need to show an image in a popup when i click this button.
Why this code doesn't work? I try with a window.open in onclick
event but it doesn't work
<input type="button" value="Mostra Immagine" onclick=window.open(src="../img/mypicture.jpg")>
Where is my error?
Share Improve this question edited Jun 7, 2017 at 12:02 Paolo Forgia 6,7468 gold badges50 silver badges59 bronze badges asked Jun 7, 2017 at 9:51 TeoTeo 411 gold badge1 silver badge6 bronze badges4 Answers
Reset to default 1You can use a fancybox to do it.
a {
color: #FFFFFF;
text-decoration: none;
}
.primary-btn {
background-image: -moz-linear-gradient(0deg, #235ee7 0%, #4ae7fa 100%);
background-image: -webkit-linear-gradient(0deg, #235ee7 0%, #4ae7fa 100%);
background-image: -ms-linear-gradient(0deg, #235ee7 0%, #4ae7fa 100%);
}
.primary-btn {
line-height: 36px;
padding-left: 30px;
padding-right: 30px;
border-radius: 25px;
border: none;
color: #fff;
display: inline-block;
font-weight: 500;
position: relative;
-webkit-transition: all 0.3s ease 0s;
-moz-transition: all 0.3s ease 0s;
-o-transition: all 0.3s ease 0s;
transition: all 0.3s ease 0s;
cursor: pointer;
text-transform: uppercase;
position: relative;
}
.primary-btn {
color: #fff;
border: 1px solid #fff;
-webkit-transition: all 0.3s ease 0s;
-moz-transition: all 0.3s ease 0s;
-o-transition: all 0.3s ease 0s;
transition: all 0.3s ease 0s;
}
.primary-btn:hover {
background: transparent;
color: #235ee7;
border-color: #235ee7;
}
<link href="https://cdnjs.cloudflare./ajax/libs/fancybox/3.2.0/jquery.fancybox.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare./ajax/libs/fancybox/3.2.0/jquery.fancybox.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare./ajax/libs/fancybox/3.2.0/jquery.fancybox.min.css">
<a data-fancybox="gallery" class="primary-btn" href="//source.unsplash./user/erondu/300x300">Demo</a>
you are missing the "
in onclick and add with _blank
for new page .passing the argument with in function using '
quotes
<input type="button" value="Mostra Immagine" onclick="window.open('../img/mypicture.jpg','_blank')">
You are using the attribute and function wrong:
onclick="window.open('../img/mypicture.jpg');"
Always quote an attribute value like you did for type
and value
.
And the window.open
function needs a path, you don't need to write "src=".
MDN - window.open()
try this:
HTML:
<div class="popup" onclick="myFunction()">Click me!
<span class="popuptext" id="myPopup">Popup text...</span>
</div>
CSS:
/* Popup container */
.popup {
position: relative;
display: inline-block;
cursor: pointer;
}
/* The actual popup (appears on top) */
.popup .popuptext {
visibility: hidden;
width: 160px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 8px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -80px;
}
/* Popup arrow */
.popup .popuptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
/* Toggle this class when clicking on the popup container (hide and show the popup) */
.popup .show {
visibility: visible;
-webkit-animation: fadeIn 1s;
animation: fadeIn 1s
}
/* Add animation (fade in the popup) */
@-webkit-keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
}
@keyframes fadeIn {
from {opacity: 0;}
to {opacity:1 ;}
}
JavaScript:
<script>
// When the user clicks on <div>, open the popup
function myFunction() {
var popup = document.getElementById("myPopup");
popup.classList.toggle("show");
}
</script>
You can read more here https://www.w3schools./howto/howto_js_popup.asp Hope Helpful