how to get the entry url on the page, after navigation? - javascript

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

Related

Redirect URL with ?aid=ind/234/ to third party URL with #affid

I need to redirect my page from abc.com/page.html?aid=ind/234/ to xyz.com/pagename#affid
I want to do this by adding meta redirect or any javascript that run locally on abc.com/page.html
I do not want to use htacess.
Please help me out.
Best Regards
use php for getting request parameter: http://php.net/manual/en/reserved.variables.request.php
and redirect to needed page like here:
How to make a redirect in PHP?
Enjoy

get url of window.history.go(-2)

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

How to get browser's current page URL from iframe?

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

iFrame Javascript Across Subdomain

I know this is a duplicate question however my requirements are slightly different,
In a previous question this was tackled by setting:
document.domain = "yourdomain.com";
on both pages.
However... I have a www.example.com domain and I have a mail.example.com
the mail.example.com is a subdomain I have no access to, it is automatically generated by my shared hosting and its where i access my emails. However I want an iframe with mail.example.com as the source on one of my pages.
e.g.
// www.example.com/mail.php
<html>
<head>...</head>
<body>
...
<? include("header.php"); ?>
...
<iframe src="mail.example.com"></iframe>
...
</body>
</html>
This works as expected but certain styles are applied to the iframe, so i want to use javascript to remove all the styles, then add my own.
But because i dont have access to mail.example.com, i cant set document.domain = "example.com"; in the sub domain.
Is there another way round this?
EDIT
I didn't make it very clear what I had already tried.
This is my exact iframe code in my mail.php page on the www.example.com domain:
<iframe id="mail" src="http://mail.a3mediauk.co.uk/mail2/source/index.php" height="800" width="960"></iframe>
This is the javascript code thats at the very top of the head element in the mail.php page:
document.domain = "http://mail.a3mediauk.co.uk";
And this is the jquery code im trying to use to remove the style:
$(function(){
$("iframe#mail").load(function(){
$("iframe#mail body").removeAttr("bgcolor");
});
});
if its any help, the document.domain throws this error in the chrome console:
Uncaught Error: SECURITY_ERR: DOM Exception 18
You probably forgot the http://
An iFrame is client-sided (HTML) so you have to enter the absolute path because it is a different domain. What you have written would redirect to http://yourdomain.com/mail.yourdomain.com.
As far as the same origin policy is concerned, the URLs have to match exactly. It doesn't matter if one is a subdomain of the other; the strings are different, so you're violating the policy.
I don't see a good solution. If the page was simple (no or only simple JavaScript, no links, etc), you can try to fetch the mail page with JavaScript into a String, strip the header (i.e. convert the body into a div) and then add that to your main page. But of course, this would break all links, the referrer, and cause lots of other problems like, say, what happens if a new version of the mail interface is installed?
Another solution would be to install a proxy service which makes everything from mail.domain.com available as your.domain.com/mail. If you run Apache on your domain, a simple rewrite rule using the "Proxy Throughput" feature should do the trick.

URL Redirection

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

Categories

Resources