Getting Full Url with #Tag

Getting FULL URL with #tag

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

How to get full url from a tag using jquery

I think you have a problem of scope when using this. You can do something like this to fix the problem. Get the n_url before making the ajax request.

$('p').click(function (event) {
event.preventDefault();
var n_url = $('a', this).attr('href');

$.ajax({
type: "POST",
url: "http://www.example.com/change_notification.php"
}).done(function (msg) {

$("#changed_notification_value").text(msg);
window.location.href = n_url;
});
});

Get the full URL in PHP

Have a look at $_SERVER['REQUEST_URI'], i.e.

$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

(Note that the double quoted string syntax is perfectly correct)

If you want to support both HTTP and HTTPS, you can use

$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

Editor's note: using this code has security implications. The client can set HTTP_HOST and REQUEST_URI to any arbitrary value it wants.

Extracting full URL from href tag in scrapy

Your code gives you a list of the URLs. The extract() method in this case gets a list. To allow scrapy to extract the data you will have to do a for loop and yield statement.

url = response.css('a[data-tracking="click_body"]::attr(href)').extract()
for a in url:
yield{'url', a}

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).

How can I get the full/absolute URL (with domain) in Django?

Use handy request.build_absolute_uri() method on request, pass it the relative url and it'll give you full one.

By default, the absolute URL for request.get_full_path() is returned, but you can pass it a relative URL as the first argument to convert it to an absolute URL.

>>> request.build_absolute_uri()
'https://example.com/music/bands/the_beatles/?print=true'
>>> request.build_absolute_uri('/bands/?print=true')
'https://example.com/bands/?print=true'

Get the current URL with JavaScript?

Use:

window.location.href

As noted in the comments, the line below works, but it is bugged for Firefox.

document.URL

See URL of type DOMString, readonly.

Is it possible to get full url (including origin) from route in VueJS?

No, not from the router.

Even the router's base property is relative to the app root:

The base URL of the app. For example, if the entire single page application is served under /app/, then base should use the value "/app/".

$route.fullPath also begins at the app root. The docs describe it as:

The full resolved URL including query and hash.



Related Topics



Leave a reply



Submit