0

I have found this code on stackoverflow, which is basically just code for baner. My question is, how to make so when when I press on banner a link opens in new tab?

Code:

<br/><br />
<a class="fragment" href="www.google.com">
<div>
    <span id='close'     onclick='this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode); return false;'>X</span>
<img src ="imgscr.com" alt="some description"/> 
<h3>Your Text</h3>
<p class="text">

 </p>
</div>
</a>

<style media="screen" type="text/css">

.fragment {
font-size: 12px;
font-family: tahoma;
height: 100px;
border: 1px solid #ccc;
color: #FFFFFF;
display: block;
padding: 10px;
box-sizing: border-box;
text-decoration: none;
background-color:#2E9AFE;

}

.fragment:hover {
box-shadow: 2px 2px 5px rgba(51, 134, 230, 1);
color:#2E9AFE;


}

.fragment img { 
float: left;
margin-right: 10px;
}


.fragment h3 {
font-size: 30px;
padding: 0;
margin: 0;
color: #FFFFFF;
position: relative;
left: 50px;
bottom: -20px;

}
.fragment h4 {
padding: 0;
margin: 0;
color: #000;
}
#close {
float:right;
display:inline-block;
padding:2px 5px;
background:#ccc;
}

</style>
i alarmed alien
  • 9,412
  • 3
  • 27
  • 40

2 Answers2

2
<a class="fragment" href="www.google.com" target="_blank ">
Budyn
  • 563
  • 7
  • 21
1

If you want to open a website:

<a class="fragment" href="www.yourwebsite.com">

If you want to open another page

<a class="fragment" href="yoursite.htm" target="_blank ">

If you want to open a page with onclick use JavaScript:

function opennewpage() {
  window.location.href='yoursite.htm'
}

than call your function with the onclick attribute:

onclick='opennewpage()'

Don't forget to include your JavaScript file to yout HTML:

<script src="yourjavascriptfile.js"></script> 
Jakob
  • 1,858
  • 2
  • 15
  • 26