Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding an onclick function to go to url in JavaScript?

I am using this fancy little JavaScript to highlight a field as the user hovers over it. Could you please tell me if there is a way of adding an onclick function which will act as a link and go to a URL?

<script>          $(function() {             $('tr').hover(function() {                 $(this).css('background-color', '#eee');                 $(this).contents('td').css({'border': '0px solid red', 'border-left': 'none', 'border-right': 'none'});                 $(this).contents('td:first').css('border-left', '0px solid red');                 $(this).contents('td:last').css('border-right', '0px solid red');             },             function() {                 $(this).css('background-color', '#FFFFFF');                 $(this).contents('td').css('border', 'none');                 $('a#read_message.php').click(function(){ URL(); });             });         });         </script> 
like image 570
John Taylor Avatar asked Oct 25 '12 15:10

John Taylor


People also ask

How do you add a link to Onclick?

Using onclick Event: The onclick event attribute works when the user click on the button. When mouse clicked on the button then the button acts like a link and redirect page into the given location. Using button tag inside <a> tag: This method create a button inside anchor tag.

Can you use onclick on a link?

This is a type of JavaScript link - the onclick attribute defines a JavaScript action when the 'onclick' event for the link is triggered (i.e. when a user clicks the link) - and there is a URL present itself in the onclick attribute.

How do I see a link onclick?

In JavaScript, to go to URL with onclick, you can use the “window. open()” method to open the window with the specified “URL” or apply the “window. location” object method to specify the location of the specified URL and the “window.

How do I link a URL to a button in HTML?

The plain HTML way is to put it in a <form> wherein you specify the desired target URL in the action attribute. If necessary, set CSS display: inline; on the form to keep it in the flow with the surrounding text. Instead of <input type="submit"> in above example, you can also use <button type="submit"> .


1 Answers

Try

 window.location = url; 

Also use

 window.open(url); 

if you want to open in a new window.

like image 62
Rick Donohoe Avatar answered Sep 18 '22 21:09

Rick Donohoe