0
I want to redirect from one page to another when the user makes a click on it, regardless of the place, however, I’m not getting
$.onclick.(function() {
window.location.href = "http://...";
});
0
I want to redirect from one page to another when the user makes a click on it, regardless of the place, however, I’m not getting
$.onclick.(function() {
window.location.href = "http://...";
});
1
You can use "vanilla js" no need for a framework, just add a listener to the "click" event in the document and use .replace()
in the object window.location
... See the example below:
document.addEventListener('click', function() {
window.location.replace('/')
}, false)
But if you prefer to use jQuery, you can map the document by tag <html>
even:
$('html').on('click', function(evt) {
window.location.replace('/')
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Sources:
0
Hello,
Put an "ID" on your body, and do the following.
$("#idBody").on("click" function() {
window.location.assign("http://answall.com");
});
0
You need to pass the instruction body
for your jQuery
to say what type of element will receive the listener
:
$('body').on('click', function() {
window.location.href = "http://...";
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.