I have been trying to get the anchor from the currect page but I can't seem to get to it. I tried using PHP code to get it but this doesn't work.
I tried all this...but none actually return the anchor or fragment

$_SERVER['HTTP_REFERER']
$_SERVER['REQUEST_URI']
$_SERVER['PHP_SELF']

Then I tried using drupal functions...I thought there has to be a function that returns the entire url....then I could break it up using parse_url(). But I can't seem to find such a function url() only returns "/". Does anyone have any suggestions on how I couldn't solve this problem. How can I get either the entire url including the anchor fragment or just the fragment?????

Comments

pwolanin’s picture

d.deman’s picture

What I mean by an anchor is the part of the url that refers to a particular part of a page. In the url "drupal.org/page?post=whatever#anchor1" the anchor part is the part after the #. This referes to a link in the page with the id "anchor1". By using an anchor you would be able to scroll to a certain part of a page automatically. The anchor is not part of the post data.

the function request_uri() returns the post data
the function arg($index) splits the path and returns the elements
the function base_path() returns "/"

neither return the anchor

mooffie’s picture

You can't. The server doesn't get to see the anchor.

Don't believe me? Experiment here:

http://delorie.com:81/type-whatever-on-your-mind-here#and-here-too

This service echoes (in your browser) the HTTP request your browser initiates.

(If you realy want to, you can use javascript tricks. Javascript resides on the browser side, so it sees the anchor.)

d.deman’s picture

damn that sux

guess I'm gonna have to get javascript'n then

pwolanin’s picture

Can you use a query string instead of an anchor?

i.e.:

www.example.com/?anchor=first

Then you can find anchor in the $_GET array.

---
Work: BioRAFT

d.deman’s picture

well.....it's part of the glossary module...it is possible....but I'm not sure I want to mess with that plus the anchor niceley makes the page scroll to the destination. I have already completely changed the glossary module so one other thing wouldn't hurt I guess...I'd have to go see how difficult it is.

pwolanin’s picture

Maybe you can use both a query string and in anchor in the links you generate- that way the browser can still easily take the user to the right part of the page.

---
Work: BioRAFT

allisonc’s picture

This is what I did, it worked, but it forces the page to reload, which kind of defeats the purpose of using anchors.

$subUrl = "/something#";

$content .= "<li><a id='$subUrl' onclick='window.location=\"$subUrl\"; window.location.reload()' style='cursor:pointer;'>My Link</a></li>";
$content .= "<script type='text/javascript'>if(window.location.pathname+window.location.hash == '$subUrl') document.getElementById('$subUrl').style.color='#ffffff'; </script>";
glass.dimly’s picture

I don't know what you were after, but for anyone else, you can get the anchor for the URL easily in javascript like so:
alert(window.location.hash);