URL detection with JavaScript

Posted by josh on Stack Overflow See other posts from Stack Overflow or by josh
Published on 2010-04-08T00:14:13Z Indexed on 2010/04/08 0:23 UTC
Read the original article Hit count: 716

Filed under:
|
|
|

Hi! I'm using the following script to force a specific page - when loaded for the first time - into a (third-party) iFrame.

<script type="text/javascript">
    if(window.top==window) {
       location.reload()
    } else {
    }
</script>

(For clarification: This 'embedding' is done automatically by the third-party system but only if the page is refreshed once - for styling and some other reasons I want it there from the beginning.)

Right now, I'm wondering if this script could be enhanced in ways that it's able to detect the current URL of its 'parent' document to trigger a specific action? Let's say the URL of the third-party site is 'http://cgi.site.com/hp/...' and the URL of the iFrame 'http://co.siteeps.com/hp/...'. Is it possible to realize sth. like this with JS:

<script type="text/javascript">
    if(URL is 'http://cgi.site.com/hp/...') {
       location.reload()
    }
    if(URL is 'http://co.siteeps.com/hp/...') {
       location.do-not.reload() resp. location.do-nothing()
    }
</script>

TIA josh

© Stack Overflow or respective owner

Related posts about url

Related posts about detection