By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,144 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,144 IT Pros & Developers. It's quick & easy.

How to use anchor tag in ajax ?

P: 62
Hello ,
My questionis short but i think many people got the same problem with me..
Is it possible to use the anchor tag in ajax ? I want the ajax load the page with specified area by using anchor tag...if yes how ?
thank you so muc
Alexander
Jan 21 '08 #1
Share this Question
Share on Google+
9 Replies


gits
Expert Mod 5K+
P: 5,333
hi ...

i think you should post an example because it is not very clear what you mean. you could use whatever node you want to start an ajax-call with any event you want that is supported by the node ... so with an anchor you could use the onclick-handler to call a function that starts the ajax-request ...

kind regards
Jan 21 '08 #2

P: 62
Hmm maybe i wrote wrong..
Ok..we talk about anormal page now..when u put the anchor tag to a page and u will get that page which specified area with forexample :
<a href ="example.php#hello">clickhere</a>

can we use this with ajax ?
Jan 21 '08 #3

gits
Expert Mod 5K+
P: 5,333
as i said already ... simply use the XMLHttpRequest to call your php-script ...

[HTML]<a href="#" onclick="make_ajax_call();">click me</a>[/HTML]
where make_ajax_call is a javascript-function that invokes the call ... what do you think of would be a problem? may be i don't get the point?

kind regards
Jan 21 '08 #4

P: 62
My problem is I want to load that page and then i want window scroll down to the topic that i want to show it first..forexample in that page that i call consist of 3 topic

test.html

topic1................
bla
bla
bla bla bla

topic2
bla bla bla

topic3
bla
bla
bla bla

i want window scroll to the topic3 after the page is loaded..is it possible ?
that why i asked about name anchor tage which can use with the normal page ....but i want to know is it possible to use with AJAX ?
thank you so much
Alex
Jan 23 '08 #5

gits
Expert Mod 5K+
P: 5,333
hmmm ... it is possible ... when the page is loaded you simply retrieve the top-coordinate of the anchor and use the scrollTo-method to scroll down ...

kind regards
Jan 23 '08 #6

P: 62
Ohh..sound great !! Do you have some example ? i really interested in what u will say..
Jan 23 '08 #7

P: 62
I forget to tell you...i know the function scroll to but how to make it work with this ?i means scroll to whereever i want proerly?
thanks again
Alex
Jan 23 '08 #8

gits
Expert Mod 5K+
P: 5,333
so assuming your anchor has an id and you use mozilla/FF:

Expand|Select|Wrap|Line Numbers
  1. var anchor_node = document.getElementById('your_id');
  2.  
  3. window.scrollTo(0, anchor_node.offsetTop);
have a look here

kind regards
Jan 23 '08 #9

P: 62
thank you so much and i will try this...:-)
Alex
Jan 24 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.