0

I got many questions same as mine, but I want really to get browser url instead of iframe url using php or jquery or javascript, any of this. I wrote several code using both php and javascript, but they not worked for me. any suggestion please?

Pritom
  • 1,294
  • 8
  • 19
  • 37
  • Do you require to retrieve the complete URL or would you want to retrieve the URL parameters? Can you be more clear on what exactly are you looking at? – Abishek Dec 24 '11 at 13:32
  • Can you some code on what you have tried already, so that people who answer dont post them again. Benefits all of us in answering better. – Abishek Dec 24 '11 at 13:51
  • such `parent.location.href`, PHP_SELF etc.......... – Pritom Dec 24 '11 at 13:58

2 Answers2

1

if you are on a single domain (browser and iframe url) then a simple window.top.location.href should return you the browser url. if the domain are different you can't retrieve any information from the parent location

malko
  • 2,292
  • 18
  • 26
  • Is there any way to know that my page is inside an iframe or not? – Pritom Dec 27 '11 at 02:12
  • you can check if window.top.location and window.location are different in which case you certainly are in an iframe (once again if parent and frame are from same domain, if not you won't be able to read the window.top.location in which case you also probably are in an iframe) – malko Dec 27 '11 at 09:26
0

Something like:

<script>
var url = window.location;
alert(url); 
</script>

will give you the page's url

See https://stackoverflow.com/a/115533/402706 for getting the parent's url while inside an iframe.

Community
  • 1
  • 1
Brandon Boone
  • 16,281
  • 4
  • 73
  • 100
  • @Pritom, Right, it will give you the url of the page it is on(parent or iframe). See the above link for getting the iframe's parent's url. – Brandon Boone Dec 25 '11 at 04:42
  • I can use `if (window.location==top.location)` to differ iframe url and browser url, but not get browser url. – Pritom Dec 25 '11 at 06:20