Pritom
Pritom

Reputation: 1333

Get browser url instead of iframe url by php or js or jquery

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?

Upvotes: 0

Views: 2240

Answers (2)

malko
malko

Reputation: 2382

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

Upvotes: 1

Brandon J. Boone
Brandon J. Boone

Reputation: 16472

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.

Upvotes: 0

Related Questions