views:

4691

answers:

4

I will only have a relative link available to me but i want to use Jquery to navigate to this rel link. I only see .ajax functionality in jquery. how can i do this using jquery or just pure DHTML/javascript?

+11  A: 
window.location.href = "/somewhere/else";
NickFitz
+2  A: 

You don't need jQuery for that, simple windows.location code will do it, e.g.:

windows.location.href = myUrl;
Nouveau
+4  A: 

Other answers rightly point out that there is no need to use jQuery in order to navigate to another URL; that's why there's no jQuery function which does so!

If you're asking how to click a link via jQuery then assuming you have markup which looks like:

<a id="my-link" href="/relative/path.html">Click Me!</a>

You could click() it by executing:

$('#my-link').click();
Ken Browning
calling click() doesn't really navigate the page for you, does it? It will run the any attached click handlers, but it won't follow the href.
Frank Schwieterman
click() generates a normal JavaScript click event so it should work, but you run into problems you try something like: $('#mydiv').click(function(){ $('#mylink').click() }); where #mylink is inside #mydiv -- this will result in an "endless" loop (really a "too much recursion" exception). If you want to navigate, it is safer to use: window.location.href = $('#mylink').attr("href");
MikeJ
A: 

I have run into a situation where I need to execute a URL change after a has completed.

I am pretty new to jquery so I am still learning it's capabilities.

I am sure someone out there has a better idea of how to do this.

 $('#overlay').animate({left:"40%",top:"45%"},'20000').delay(40000).GETURL("http://myurl.com");

I would like to have an onComplete type of function that can fire once something has finished.

$('#overlay').animate({left:"40%",top:"45%"},'20000').onComplete(completedFunction);

Any help would be great

Eryx
You need to ask your own question in StackOverflow, not just glom it on to the end of someone else's question. But for the record, jQuery animation functions all take a parameter which is a function to execute at the end of the animation. So you do it like this: $('#overlay').animate({left:"40%",top:"45%"},'20000',function(){ /*do stuff when animation complete*/ }); The jQuery function reference is online and makes stuff like this very clear -- suggest you check it out.
MikeJ