PDA

View Full Version : Lyteframe: Check if page is loaded direct?



blackfive
04-07-2011, 06:57 AM
I'm using lytebox/lyteframe to open sub-pages and very nice it is too but I'm finding that visitors are reaching the sub-pages directly from search engine results and, obviously the sub-pages lack navigation to the rest of the site which I would like visitors to see.
Now I could always stop search engines from indexing the sub-pages using robots.txt but I don't want to do that as it would loose me visitors so what I would like to do is detect if a page is loaded in a lyteframe or has been loaded directly then, if direct, redirect visitors to the index page and my html/javascript/etc. simply isn't up to it!
If that's not a possibility, is there a way to have a message appear on the page (or as a pop-up) only if the page isn't loaded in a lyteframe?
Any ideas would be greatly appreciated.

jscheuer1
04-07-2011, 03:49 PM
On the sub-pages put:


<script type="text/javascript">
if(top.location.href === location.href)
location.replace('/');
</script>

That's assuming the index page is in the root of the domain and has a name like index.htm, or index.html, etc. that makes it the default page. If in doubt, you may use the absolute path to the page you want to redirect to, ex:


<script type="text/javascript">
if(top.location.href === location.href)
location.replace('http:/www.mydomain.com/index.html');
</script>

But the relative path or the network path (as in the first code block) is preferred for compatibility reasons.

blackfive
04-07-2011, 09:50 PM
I'll try that when I get back to my PC next week. Many thanks.
EDIT.....
Again, many thanks. Works an absolute treat. Just what I needed to do!
I'll know where to come the next time I get stuck.