-4

I have linked a site which redirects the browser to another server with a parameter "access_token" e.g.

http://somedomain.com/blank.html#access_token=sadf2342dsdfsd

How can I get this parameter from the URL before the page is redirected to the other server?

Ozzy
  • 8,244
  • 7
  • 55
  • 95
iStark
  • 65
  • 1
  • 1
  • 6
  • 1
    @GabrielSantos its 20% now :) – Ozzy Apr 14 '12 at 22:45
  • Good! To Stack Overflow become a better place, always accept the answers that solve your problems. This helps those looking for something similar to what you asked to solve their problems too. – Gabriel Santos Apr 14 '12 at 22:47

3 Answers3

1

I don't clearly understand you question. Though I have som suggestions to the way of getting the access_token parameter from the URL.

Provided that you know the url, you can just explode the string and get the access_token.. It could look something like this:

echo end( explode('#', 'http://somedomain.com/blank.html#access_token=sadf2342dsdfsd'));

If your are directly at the site, you can use javascript to get the hash:

document.location.hash.substr(1)
hskrijelj
  • 433
  • 5
  • 16
  • so if I on http://somedomain.com/blank.html#access_token=sadf2342dsdfsd where I should paste this document.location.hash.substr(1) ? On my site from I redirected? – iStark Apr 14 '12 at 22:34
  • I don't understand where you are going with this, sorry. Is somedomain.com/blank.html#access_token=sadf2342dsdfsd your site, where you got access to the blank.html? If so, you should just put in the js-code in the blank.html-file. Perhaps with document.write: – hskrijelj Apr 14 '12 at 23:27
1

I think you are trying to access the address bar of a clients browser AFTER it has left your website?

That won't be possible unless you open the site in an iframe and then access the child frame with javascript.

You can do that easily by changing the target of your link, e.g.

Change this:

<a href="http://thewebsite.com/">Go to website</a>

To this:

<iframe name="tokenFrame" id="tokenFrame" width=1 height=1 frameborder=0> </iframe>
<a href="http://thewebsite.com/" target="tokenFrame">Don't go to website</a>

Then in javascript, after the page has changed to the one with the token:

var url = document.getElementById("tokenFrame").src

Or something similar to get the location e.g.

var frame = document.getElementById("tokenFrame");
var url = frame.top.location.href;

Or

var url = top.tokenFrame.location.href;

Finally parse the URL to get the value

Ozzy
  • 8,244
  • 7
  • 55
  • 95
0

In javascript you can grab the value of it like this

window.location.hash.replace('#access_token=','')
GillesC
  • 10,647
  • 3
  • 40
  • 55