Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

redirect in jquery

Posted on 2011-10-16
10
Medium Priority
?
320 Views
Last Modified: 2012-05-12
<a id="aa" href="http://www.google.com">go go</a>

I want this go to yahoo.com, what do I do with jquery? I don't want javascript, only jquery.


$(document).ready(function(){

   $('#aa').click(function(){

      what code ?      

   });


});
0
Comment
Question by:charmingduck
  • 6
  • 4
10 Comments
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36975864
try

window.location.href='http://www.yahoo.com';
0
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36975874
here is the working code....
 
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title> - jsFiddle demo</title>
  <script type='text/javascript' src='http://code.jquery.com/jquery-1.6.4.js'></script>
  
  <link rel="stylesheet" type="text/css" href="/css/normalize.css">
  <link rel="stylesheet" type="text/css" href="/css/result-light.css">
  
  <style type='text/css'>
    
  </style>
  
  <script type='text/javascript'>
  //<![CDATA[ 
  $(window).load(function(){
  $('#aa').click(function(){
    event.preventDefault();
    window.location.href="http://www.yahoo.com";
});
  });
  //]]> 
  </script>
  
</head>
<body>
  <a id="aa" href="www.google.com">Click here</a>
  
</body>


</html>

Open in new window

0
 

Author Comment

by:charmingduck
ID: 36975900
sorry, it did not work.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 13

Expert Comment

by:ansudhindra
ID: 36976048
Sorry, above script is working fine in chrome.
Below one works both in IE and chrome..
 Replace the script block with the below code...
<script type='text/javascript'>
  //<![CDATA[ 
  $(window).load(function(){
  $('#aa').click(function(){
    if(event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; }
    window.location.href="http://www.yahoo.com";
});
  });
  //]]> 
  </script>

Open in new window

0
 

Author Comment

by:charmingduck
ID: 36976258
still not working
0
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36977718
which browser you are using? or how your are testing it?
0
 

Author Comment

by:charmingduck
ID: 36978055
I tested it chrome and firefox and safari, put the code in php enabled editor.

In drupal7

(function ($) {

$(window).load(function(){
  $('#aa').click(function(){
    if(event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; }
    window.location.href="http://www.yahoo.com";
});
  });


})(jQuery);
0
 
LVL 13

Assisted Solution

by:ansudhindra
ansudhindra earned 500 total points
ID: 36978319
I dont know how it is in Drupdal,.. but try like this....

(function ($) {

  $('#aa').click(function(){
    if(event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; }
    window.location.href="http://www.yahoo.com";
});


})(jQuery);
0
 

Author Comment

by:charmingduck
ID: 36979257
great, this worked!!

how do i make this open a new window?
0
 
LVL 13

Accepted Solution

by:
ansudhindra earned 500 total points
ID: 36979358
that's quite simple..
use window.open method like below..

(function ($) {

  $('#aa').click(function(){
    if(event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; }
    window.open("http://www.yahoo.com");
});


})(jQuery);
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Conducting a customer service survey used to be as straightforward as sending a template email out using checkboxes and numerical rating systems to measure satisfaction.
Use this step by step method when setting up QuickBooks Online. They will allow you to explore the various features of the advanced settings available to you.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question