Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting FULL URL with #tag

Tags:

php

Tried to print the $_SERVER array in PHP, yet I can't find what I want:

http://www.domain.com/#sometaginpage

I want the "sometaginpage".

Help. Thanks!

like image 484
JoHa Avatar asked May 25 '11 03:05

JoHa


People also ask

How to get the full URL of the current page?

You can get the full URL of the current page using the the window.location.href property. You can get the domain name from the URL of current page using the window.location.hostname property. You can get the pathname from the current URL a visitor is on using the window.location.pathname property.

How do I enable full URLs in Google Chrome?

This option requires enabling a hidden flag in Google Chrome. To find it, copy-paste the following text into Chrome’s address bar and press Enter: To the right of “Context menu show full URLs” on the Flags page, click the box and select “Enabled.” Click “Relaunch Chrome” to restart the browser.

How to-get current URL with JavaScript?

How TO - Get Current URL With JavaScript ❮ PreviousNext ❯ Learn how to get the current URL with JavaScript. Current URL Use window.location.hrefto get the current URL address: Example document.getElementById("demo").innerHTML = "The full URL of this page is:<br>" + window.location.href; Try it Yourself »

What's the best way to get the full URI of a URL?

Get the full uri with schema, host, port path and query. As mentioned in other answers, request.build_absolute_uri () is perfect if you have access to request, and sites framework is great as long as different URLs point to different databases. However, my use case was slightly different.


2 Answers

The browser doesn't actually send anything that comes after the hash(#) to the server because it is resolved within the browser.

like image 65
Sean Walsh Avatar answered Oct 13 '22 01:10

Sean Walsh


Fairly certain that #hashtags are NOT sent to the server, but you could develop a workaround with AJAX:

some-page.html:

<script type="text/javascript">
    $(document).ready(function() {
        $(window).bind('hashchange', function() {
            var hash = window.location.hash.substring(1);
            $.get('ajax-hash.php', { tag: hash },
                function(data) { $('#tag').html(data); }
            );
        });
    });
</script>

<div id="tag"></div>
<a href="#one">#one</a> | <a href="#two">#two</a> | <a href="#lolwut">#lolwut</a>

ajax-hash.php:

<?php
    $hash = isset($_GET['tag']) ? $_GET['tag'] : 'none';
    echo $_SERVER['HTTP_REFERER'] . '#' . $hash;
?>

Note: This is dependent on the browser actually sending the HTTP_REFERER.. Since it's done through jQuery, it SHOULD.. but no promises! (Antivirus/Firewalls love to strip that from your packets)

like image 29
drudge Avatar answered Oct 13 '22 00:10

drudge