how to call a url using on click event

Hi,

How to call  an  url or a page  from a Jquery  on click event.


Thank you
roy_sanuAsked:
Who is Participating?
 
chaitu chaituConnect With a Mentor Commented:
$('#Test').click(function() {
  window.location = 'http://www.google.com'
  return false;
});
0
 
Marco GasiFreelancerCommented:
window.loaction returns the actual url. You have to use one of the following:

window.location.assign('http://www.google.com');
or
window.loacation.href = 'http://www.google.com';
or
window.loacation.replace = 'http://www.google.com';

$('#Test').click(function() {
  //choose one and uncomment it
  //window.location.assign('http://www.google.com');
  //window.loacation.replace = 'http://www.google.com';
  window.loacation.href = 'http://www.google.com';
  return false;
}); 

Open in new window

0
 
roy_sanuAuthor Commented:
suppose i have a url path such as /jsp/user.html

can i use like this

$('#Test').click(function() {
  window.location = "/jsp/user.html"
  return false;
});
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
chaitu chaituCommented:
yes.

or you can use window.location.href = "/jsp/user.html"
0
 
Marco GasiFreelancerCommented:
I'm sorry: I always used window.location only to get current page url :-(
I sign off from this question, now.
Cheers
Marco
0
 
RawbinCommented:
You can use like this:

<button onclick="myFunction()">Click to Open New Window</button>

<script type="text/javascript">
function myFunction() { window.open('www.sample.com', '_blank', 'toolbar=1,location=0,menubar=0'); }
</script>

www.sample.com => your website
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.