2
As you can see in that fiddle For example, when the first link is clicked a div appears and when pressing the browser back button, it closes. I would like the second link to work in the same way, showing the two div, but when I try to duplicate the function one of the two stops working and I have no idea why (I am a layman in JS/Jq). Can you help me?
Fiddle link: https://jsfiddle.net/d6yp3b92/
Code:
$(document).ready(function() {
$('body').on('click touch', '#paginaUm', function(e) {
$('.pagina.um').fadeIn();
});
});
// geri butonunu yakalama
window.onhashchange = function(e) {
var oldURL = e.oldURL.split('#')[1];
var newURL = e.newURL.split('#')[1];
if (oldURL == 'paginaUm') {
$('.pagina.um').fadeOut();
e.preventDefault();
return false;
}
//console.log('old:'+oldURL+' new:'+newURL);
}
.pagina{position:fixed; display:none; top:0; left:0; width:100%; height:100%; background:gray; color:white; padding:20px;
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="#paginaUm" id="paginaUm">Pagina 1</a>
<div class="pagina um">
<h1>Popup 1</h1>
<p>Pressione voltar para fechar.</p>
</div>
<a href="#paginaDois" id="paginaDois">Pagina 2</a>
<div class="pagina dois">
<h1>Popup 2</h1>
<p>Pressione voltar para fechar.</p>
</div>
If each
<a>
opens the<div>
that is inside so you do everything with a click event if you change a little the classes you have.– Isac