How to fetch Referrer URL's Title - javascript

How do we get the title of referrer URL page? I can get the referrer by
var referrer = document.referrer;
but unfortunately there's no (document.referrer).title available in javascript similar to document.getElementsByTagName('title')[0].innerHTML.
Any ideas how I can get this value?

If any information about the referer is passed to JavaScript then it will be nothing more than the URL.
To get the title of the page you will need to make an HTTP request to it and parse it out of the HTML.
If you make this HTTP request from JavaScript then it will be subject to the Same Origin Policy (with the usual work-arounds applying).

Related

Getting referrer in asp net mvc

I need to get referrer , when user is redirected from other site to my own , i trying get referrer from headers but its empty. All attempts returns null or empty :
Request.UrlReferrer
HttpContext.Current.Response.Headers["Referer"].ToString()
ServerVariables["http_referer"]
and if you look to request headers in browser , i will not find referrer header.
tried get referrer from javascript document.referrer but its returns empty string
can somebody please explain why there is no referrer header and how i can get it ?
Usually, Referrer URLs are passed between two unrelated sites (from one site to another) when navigation occurs by clicking a link or JavaScript-based navigation. Referrer URLs are not sent if the user uses the browsers address bar, back/forward buttons/ etc.. to navigate.
There are several reasons why the Referrer URL is empty in a request.
For some (security/privacy) reasons, the Referrer URL is stripped out
when navigating from a HTTPS site to a HTTP site (e.g. from
https://google.com to http://example.com).
It can also be stripped out using some other JavaScript
and HTML tricks.
once Referrer URL has been stripped out, There is no way to disable this behavior to get it back.

JS - How to get URL of redirect

Hi I'm trying to find a way to get the URL of a redirected webpage.
Ex/ I type in a url to my web browser, "http:foo.com", and it redirects me to "http://foo.com/bar".
How can I use fetch or something else to have "http://foo.com/bar" returned to me? (The website I'm trying to receive the url from "has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."
Please and thanks in advance for ideas / solutions.
You can't. XMLHttpRequest and fetch silently follow redirects, and no information about the final URL is available in the object afterwards.
Even if that information was available, the Same Origin Policy would prevent you from accessing it (as the error message indicates).
Use a server side technology instead.

How does Google sets HTTP Referrer after a search result click

For example, the first search result on this page leads to the older SO question, with the following HTTP request:
GET /questions/4402502/how-does-google-set-the-http-referrer-when-someone-clicks-on-a-search-result-lin HTTP/1.1
Host stackoverflow.com
Referer https://www.google.ru
Note, that:
Only the domain is included in the Referer header, no query string.
Google is open via HTTPS, while SO is open via plain HTTP - nevertherless, the Referer header is sent by the browser.
There are no server-side redirects involved, the first HTTP query to open after the click is to the target site.
The question is, how do they achieve this?
Google makes use of Referrer Policy.
They include the meta tag in the page:
<meta name="referrer" content="origin">
This tells browsers to use "Origin Only" policy, that is, to send domain only information in the Referrer header in any subsequent request.

How to get the url in browser address bar in nodejs

I am displaying a page in an iframe, and in my Node.js server I need to access the main page's URL.
I do not want to get the request URL for the page in the iframe, but I need the URL in the browser's address bar, the one for the main page.
The Referer request header should contain the URL you are looking for.
http://www.nczonline.net/blog/2013/04/16/getting-the-url-of-an-iframes-parent/
The HTTP Referer header for a page inside of an iframe is always set to the containing page’s URL.
try the Url module ctrl-f 'pathname' from this page http://nodejs.org/api/url.html

Load an external html to string in javascript

Is it possible to load for example google.com to a javascript variable?
var html = "the html of google.com"
Is this possible?
Update:
What about in an air application?
Not unless you send the source from the server.
From javascript, it will violate the Same Origin Policy. You can send the request, and you'll get a response, but the response will be empty.
If it's a page in the same domain you're in, then yes. Otherwise, not without some special URL provided by the target domain that sends you pages based on some form of special request.
You can always have your own server fetch the page and forward it to your client.

Categories