I've set the following links (found on DEMO) to open in the same tab by using the "_top" target (tried "_parent" as well, but for some reason they keep opening in a new tab. I've tried different browsers, and different devices but it still happens.
$(document).ready(function() {
// for slide-out menu
$('.js-nav').click(function() {
$(this).parent().find('.menu').toggleClass('active');
if ($(this).find('i.fa').hasClass('fa-bars')) {
$(this).find('i.fa').removeClass('fa-bars').addClass('fa-times');
} else if ($(this).find('i.fa').hasClass('fa-times')) {
$(this).find('i.fa').removeClass('fa-times').addClass('fa-bars');
}
});
});
html,
body {
width: 600px;
height: 50px;
}
.toggle-nav {
margin: auto 0 auto 0;
float: left;
color: #423c4c;
}
.toggle-nav:hover {
color: #423c4c;
}
.nav-wrap {
overflow: hidden;
}
.menu {
float: left;
visibility: hidden;
position: relative;
right: 100%;
transition-duration: 5s;
-webkit-transition-duration: 5s;
}
.menu.active {
visibility: visible;
right: 0px;
transition-duration: 1s;
-webkit-transition-duration: 1s;
}
.menu ul {
text-align: justify;
min-width: 400px;
margin: 0 auto;
padding-right: 20px;
}
.menu ul:after {
content: '';
display: inline-block;
width: 100%;
}
.menu ul li {
margin-top: 2%;
display: inline-block;
text-align: center;
text-transform: uppercase;
font-family: 'Alef', sans-serif;
font-size: 13px;
color: #423c4c;
}
.menu ul li a:link {
color: #423c4c;
text-decoration: none;
}
.menu ul li a:visited {
color: #423c4c;
text-decoration: none;
}
.menu ul li a:hover {
<!-- border-bottom: 1px solid #423c4c;
-->text-decoration: none;
background-color: #fce2e2;
;
color: red;
}
.menu ul li a:active {
color: #423c4c;
}
.menu ul li ul {
display: inline-block;
position: absolute;
right: 272px;
top: 25px;
}
.menu ul li ul li {
display: table;
font-size: 13px;
right: 0px;
text-align: right;
background-color: #fce2e2;
padding: 5px;
margin-top: 0px;
word-spacing: 1px;
min-width: 130px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet"/>
<a class="toggle-nav js-nav" href="#/"><i class="fa fa-bars fa-2x"></i></a>
<div class="nav-wrap">
<nav class="menu">
<ul>
<li>
<a href="http://google.com" target="_top">link1</a>
</li>
<li>
<a href="http://pinterest.com" target="_top">link2</a>
</li>
<li>
<a href="http://www.awwwards.com" target="_top">link3</a>
</li>
<li>
<a href="http://dribbble.com" target="_top">link4</a>
</li>
</ul>
</nav>
</div>
Please help.
Thanks
Mey
Your problem stems from the presence of the sandbox attribute on the iFrame used by JSFiddle and other such sites including StackOverflow's StackSnippets.
Your code works when stand alone like here
By having the attribute set but NOT having the allow-top-navigation set, it is not allowed to break out of the frame except to a new window/tab
https://developer.mozilla.org/en/docs/Web/HTML/Element/iframe