views:

35

answers:

2

how to see the current URL from browser?

Is the user coming to my page directly via www.mypage.com/myapp or through apps.facebook.com/myapp

+2  A: 

Is this javascript?

You can use:

alert(location.href);

Or:

alert(document.referrer);

The first one shows the current location while the second shows (as you asked) where the user came from.

Edit: I see you tagged as Asp.net, when you are doing client-side coding, there's no ASP.NET but only javascript (strictly speaking, but ASP.NET may control client side via AJAX/JS).

With my solution above note that you can't get the browser location if in an iframe (unless on the same domain), due to cross-domain policy.

Christian Sciberras
thanks but I am doing server side asp and need to make there IF (browser url =xxx)..
Tom
A: 

In JavaScript document.referrer holds the site from which the user came to your page. If your page is embedded in the page (not in an iframe) window.location.href holds the url string of the browsers current location.

clusterfu_k