How to get a referrer URL on Angular 4?? For example say example.com is my angular website, if example.com is visited from an another php page say domaintwo.com/checkout.php. How can I identify the the referenced url(domaintwo.com/checkout.php) from my angular website..?? Am looking for a solution like $_SERVER['HTTP_REFERER'] on PHP(same process needed on angular4). Thanks in Advance
Have you tried?
document.referrer
According to W3C:
referrer of type DOMString, readonly
Returns the URI [IETF RFC 2396] of the page that linked to this page. The value is an empty string if the user navigated to the page
directly (not through a link, but, for example, via a bookmark).
Related
I want to detect direct access to my page using javascript
because I want to remove a <div> ... </div> if someone directly accessed my page
I searched and I found this: how can I check if page accessed directly on stackoverflow
and I found a website doing the same thing I want is detecting if it is a direct access to the page or not but I don't know how they do it
If you mean if it's a user, check for the X-Requested-By header in the document's request.
If you mean if it's a direct URL typed in, check for the Referrer header.
I used window.history.go(-2) it redirects but I don't want to redirect I want to print the URL (to know the referrer), Example: I'm navigate file1->file2->file3, I wrote the script window.history.go(-2) in file3, and I want the alert as 'file1'. Can anybody help me please?
If not possible is there a way to get the referrer URL, and I'm in a iframe, from the frame I want the sites referral URL.
It is a violation of privacy and it is not possible easily.
You can read this to check the history of similar attempts. Nowadays it is way harder.
It is possible to go back the browser history via history.go, but not to get the url locations from it. However, if you click some link and entered the page, you can use the document.referrer property to get the referrer url. Refer this link for more info.
Difference between document.referrer and window.parent.location.href
Ok. This might have been asked several times but my problem is slightly different. I have following page tab in my facebook application:
Facebook Page Tab
This facebook page tab has my website embedded as iframe into it. What I want is that is to get the URL of current page inside my application.
For example, if you open above link you see facebook URL in your browser(obviously) address bar. In my iframe I just want to retrieve the URL of the parent page in which it is embedded.
I know same-origin policies in Javascript don't allow playing with cross-domain parent page's markup using javascript but I just want to retrieve the parent page URL, thats it.
Is that possible in ANY way?
Any way to access the address bar URL in my PHP application?
Thanks.
You probably don’t need the “actual URL”, but only the page id, I assume …? That you can get by decoding the signed_request parameter that gets POSTed to your app on initial load into the iframe.
How to “decode” it is described here, https://developers.facebook.com/docs/facebook-login/using-login-with-games#parsingsr
If you’re using the PHP SDK, that has a method already that does this for you.
You can use this to access it in JavaScript:
top.location.href
"top" is better than "parent". Because if your iframe is itself in another iframe then parent will return that iframe's location. "top" will return the highest location.
This will be a tough one, because CORS forbids to access the outside frame:
The referrer doesn't help very much either.
If you want to use the signed_request, and want to send custom data/parameters to your app, have a look at https://developers.facebook.com/docs/appsonfacebook/pagetabs#integrating
You can then fill the app_data parameter, and decode that in your app.
Try one of these:
parent.document.location
parent.window.document.location
parent.window.location
parent.document.location.href
I'm not sure if this will work on facebook though
For ex: My website is www.mydomain.com
the only thing on the page is
<h1>Category</h1>
When a user types in the url www.mydomain.com/sports I would like for the page www.mydomain.com to load (with or without the /sports path, preferably keeping the same URL the whole time) and know that the user accessed the page using the url www.mydomain.com/sports to get there.
At which point, I could then use javascript to change
<h1>Category</h1>
to
<h1>Sports</h1>
I am able to redirect the page www.mydomain.com/sports to www.mydomain.com, but when doing this the URL changes and I can't detect the page URL that was used initially to navigate there (www.mydomain.com/sports) using javascript: http://www.w3schools.com/jsref/obj_location.asp since it returns the new page URL without the path.
Am hoping for a non PHP/.htaccess solution.
UPDATE:
I resorted to using htaccess to fix the problem, was easier than expected to implement.
Here's what I used in case someone else finds this useful
.htaccess file (upload to the directory on your site where you want it to be used, in my example, that would be the main directory)
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase / ****start at/find the root directory
RewriteRule ^(/sports|sports/)$ index.html [NC,L] ****find and clear index.html from URL if the extension is mydomain.com/sports or mydomain.com/sports/
</ifModule>
Take a look at this plug-in.
http://html5doctor.com/history-api/
History.js
This plug-in allows you to push a new URL onto the history of the browser (in a cross-browser compatible fashion) without actually refreshing the page.
Therefore your approach would be as follows.
List item
On load, Get the window.location to get the "Sport"
Push the www.mydomain.com onto the history stack (using history.js)
Change the h1 to "Sport".
The only issue with this approach is that if someone tries to bookmark the page, it will not be the content that they encountered the last time they navigated to the URL. This however may be the point of what you're proposing in your question.
Your server-side code should use add a setCookie header having the value of the category that you want to display. Then your javascript code can get the cookie and set the field appropriately.
I have recently read Google's Making AJAX Applications Crawlable as I was wondering how to correctly prepare my dynamic site, which uses hashbang navigation, for SEO.
I understand now that for mysite.com/#!/foobar I should serve an equivalent html snapshot at mysite.com/?_escaped_fragment_=foobar.
I just want to know if google then correctly indexes my page as http://example.com/#!/foobar
or if it uses this escaped_fragment url? I'm assuming (but would like to be sure) it will correctly use my hashbang url for the search results but that the indexed content was taken from the escaped_fragment page.
Some confirmation would help me sleep better. thanks
By default, google will create escaped_fragment url for your page. That could end up looking ugly.
You should redirect escaped_fragment url to a page page with a prettier url using 301
Say your server gets a URL request from googlebot/any hashbang compliant crawler such as "targetPage?_escaped_fragment_=command=play%26id=4ee7af"
You should have your targetPage accepts targetPage?_escaped_fragment_= .... and created a 301 redirect to itself as "targetPage?command=play&id=4ee7af" ( or any other pretty url as long as it is to the same page)
If you were using J2EE you could create a servlet filter to intercept and 301 redirect to cleaner url of the same page.