By d.deman on
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
API site
I'm not quite clear what you mean by "anchor", but look at these functions:
http://api.drupal.org/api/4.7/function/request_uri
http://api.drupal.org/api/4.7/function/arg
http://api.drupal.org/api/4.7/function/base_path
---
Work: BioRAFT
what I mean by an anchor
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
...
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.)
damn that sux guess I'm
damn that sux
guess I'm gonna have to get javascript'n then
use a query string?
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
It's part
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.
use both?
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
This is what I did
This is what I did, it worked, but it forces the page to reload, which kind of defeats the purpose of using anchors.
I don't know what you were
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);