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?

3
  • 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? Commented Dec 24, 2011 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. Commented Dec 24, 2011 at 13:51
  • such parent.location.href, PHP_SELF etc.......... Commented Dec 24, 2011 at 13:58

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Is there any way to know that my page is inside an iframe or not?
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)
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.

2 Comments

@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.
I can use if (window.location==top.location) to differ iframe url and browser url, but not get browser url.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.