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
Related
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).
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
I am encouraging people to embed my website on their own using an iFrame. What I need to do is to let the Javascript on my page find out their domain. So if they embed my page on http://yahoo.com then I need to be able to fetch that address.
How to?
I tried various things such as parent.window.location, window.location etc. But all I get is the address to my page in the iFrame.
window.parent.document.location would give you the url
try this:
window.opener.document.location
or
window.parent.document.location
I am trying to achieve something like, that is on the below link.
http://www.laterooms.com/
This website is at the above URL.
But even if you type .co.uk or
.net or
.org Like this any Extension. The URL will be automatically redirected to
http://www.laterooms.com/
First of all, you should be in possession of the other domains (with the extensions you want). Then you can either use javascript to set top.location.href='http://your.address.com/' or use other means, like setting up your web server to redirect the requests, or your domain name registrar.
You can either use different techniques on server side to force a redirect, or you can send a page containing a redirect Refresh: 0; url=http://www.example.com/
Wikipedia has a good overview on this.
<head>
<meta http-equiv="refresh" content="5; URL=http://de.selfhtml.org/">
</head>
If you own/have possession of those other domains..
You could set forwarding (dns settings) for each of the domains you wish to redirect to the primary domain.
That would get you away from having to code a page for each one of those domains.
Much cleaner, and easier.
Assuming you own all the domains, and they all point to the same webserver, then this code should do it;
var href_parts = top.location.href.split('/');
if (href_parts[2] != 'www.laterooms.com') {
href_parts[2] = 'www.laterooms.com';
top.location.href = href_parts.join('/');
}
Basically -- have javascript test what domain you currently are on, and if not on the .com then update the URL and store it back into the location.href for the page which will automatically trigger a page-reload with the new URL.
The above code preserve the URL path within the domain, so if somebody types in
http://www.lateroom.co.uk/mypath/here
will redirect to
http://www.lateroom.com/mypath/here
If you don't want to preserve the path /mypath/here then the code will be sligthly simpler as you can just hardcode the destination path rather than using the join
I have the following scenario:
I want to pass a parameter to a pagefoo.com?bar=x, but foo.com automatically redirects based on language to foo.com/en and I am loosing the bar parameter.
I don't mind I'm in foo.com/en, I just want the bar parameter.
The Referer solution does not work, as it automatically redirects, and it's the one before foo.com?bar=x.
Is there a JavaScript or jQuery solution to this problem?
edit
I just have a script on the page, foo.com is not my domain, I have the script on both foo.com and foo.com/en. The problem is that on foo.com the script does not get called, and on foo.com/en I don't have the parameters any more.
The page foo.com redirects by this method:
<meta http-equiv="Refresh" content="0;URL=foo.com/en" />
I can't modify this method, and I don't want to, as the solution would not be generic.
No, there isn't.
If foo.com?bar=x and foo.com?bar=y should have different content, then they shouldn't redirect to the same resource.
Have you tried changing the redirect so that it includes anything after the domain name e.g. the script name, querystring, etc. in the redirect?
Found the solution, it was much easier, just change from
foo.com?bar=x
to
foo.com#bar=x
This way, the hash tag remains, so I have foo.com/en#bar=x
Thank you for your answers.
You could use a PHP catch...
If you have
foo.com?bar=x
and you want to redirect to
foo.com/en?bar=x
use this
<meta http-equiv="Refresh" content="0;URL=foo.com/en?bar=<?php echo $_GET["bar"]; ?>" />
the resulting redirect will be
foo.com/en?bar=x