Get Entire Url, Including Query String and Anchor

Get entire URL, including query string and anchor

No, I am afraid not, since the hash (the string including the #) never gets passed to the server, it is solely a behavioural property of the browser. The $_SERVER['REQUEST_URI'] variable will contain the rest however.

If you really need to know what the hash is, you will have to use the document.location.hash JavaScript property, which contains the contents of the hash (you could then insert it in a form, or send it to the server with an ajax request).

Proper URL forming with a query string and an anchor hashtag


?var=var#hash

Everything after # is client side.

Also, look into URL rewriting to get rid of ugly ?var=var.

Is it possible to access anchors in a querystring via PHP?

No, there isn't a way. The fragment part (the label after #) is not transmitted to the server.

The browser retrieve the document http://power-coder.net/Test/something.php?id=3 and then go to the correct anchor (if there is one) in the document.

I want to append the query string on a URL to all anchor links on the page

How about using querySelectorAll in vanilla javascript instead of jquery. Also, kill your leading '?' in querystring. And if part of your question involves how to get the querystring from the current page's url, use window.location.search.

In the snippet below, you have some google search anchors. One searches 'x', and the other searches 'y'. Your query string further specifies that in both anchors, you want a safe search for images.





// You will use window.location.search

let querystring = '?tbm=isch&safe=active'


if(querystring.startsWith('?'))

querystring = querystring.replace('?', '');


for(let a of document.querySelectorAll('a')) {

a.href +=

(a.href.match(/\?/) ? '&' : '?') +

querystring;

}
<a href='https://www.google.com/search?q=x'>search x images safely</a><br/>

<a href='https://www.google.com/search?q=y'>search y images safely</a>

c# get complete URL with #

Your problem is that # specified an anchor in the page, so the browser sees:

http://localhost/site/page.aspx?var=1&var=2

And then looks in the page for

<a name="link">anchor</a>

As this is client side you need to escape the # from the URL - you can't get it on the server because the browser's already stripped it off.

Getting the full url of the current page with url hash on server side

there is no way to get hash content on server side because hash are never posted to the server

see this question for some tricks How to get Url Hash (#) from server side

create query string in anchor tag


<a class="jt" href='WorkExp.aspx?Emplid=<%= Request.QueryString["Emplid"] %>'>Previous Work Experience</a>


Related Topics



Leave a reply



Submit