Ed Vizenor
Ed Vizenor

Reputation: 20

JavaScript getting the URL in browser from an iframe

I am using a free site. that free site has a free app. In that free app I can run PHP code from my server.

What JavaScript code can get me the URL of the address showing in browser called from an iframe on my server?

Thanks -Ed

Upvotes: 0

Views: 2430

Answers (2)

Neil
Neil

Reputation: 55402

var addressBarURL = top.location.href;

Upvotes: 0

Oliver Moran
Oliver Moran

Reputation: 5167

If I understand you right, you want to get the URL of the main window from the iframe. If so (from the page in the iframe):

window.parent.location.href

NB: Security policies on browsers will not allow you to access the this property if the main window and the iframe are accessed on different domains.

Upvotes: 6

Related Questions