JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old July 28th, 2005, 07:30 AM
Pewit Pewit is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 1 Pewit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 33 sec
Reputation Power: 0
Frames and translated pages

Hi There

I have two frames - topFrame containing menus and mainFrame with the content. I use frames on my site because:
- It speeds up the load (the menu and logo appears while the rest loads) and allows the navigation stuff to only load once.
- It allows me to put all the search engine optimisation stuff in the no-frames content without affecting the load time of the main page display.

My problem is that I want to provide an option for users to translate my content using the Google translation tools. I found a great script to do this (below). My problem is that Google creates a frame on the top of the translated page and I need to be able to remove this if the user clicks on the "Original English" button.

The script below is saved in a file translate.js which is called by another script in the mainFrame on load so it writes the flag buttons.

My feeling is it requires a modification of the line
"if (top != self &&"
but I can't see how to change this to target my mainFrame.


var flag_folder_url = "http://mydomain.com/images/";
var flag_alignment = "h";
var to_translaton_heading = "Click flag to translate<br>";
var to_original_heading = "Click flag for Original<br>";
// SCRIPT BEGINS -- DO NOT CHANGE AFTER THIS POINT
// Function returns a single HTML-formatted hyperlink using a flag graphic.
function translation_link(hl_equals,lp,flag_file,title)
{
var orig_url = document.location.href;
orig_url = orig_url.slice(7, orig_url.length);
escape(orig_url);
if (orig_url.search("%3F") > -1)
orig_url = orig_url.slice(0, orig_url.search("%3F"));
translation_url = "http://translate.google.com/translate?u=http%3A%2F%2F"
// + hl_equals
+ orig_url
+ "&langpair="
+ lp
+ "&hl=en&safe=of&ie=UTF8"
+ "&prev=%2Flanguage_tools";
full_link = "<a href='" + translation_url + "' title='" + title + "'>"
+ "<img src='" + flag_folder_url + flag_file + "' width='20' height='10' border='0' hspace='1'>"
+ "</a>";
if (flag_alignment == "v")
full_link = full_link + "<br>";
return (full_link)
}
// If the page has not been loaded by Google's translator, then write the link flags.
if (document.location.hostname != "216.239.39.104" &&
document.location.hostname != "216.239.37.104" &&
document.location.hostname != "translate.google.com")
{
trans_links = translation_link("de","en|de","fl_de_sm.gif","Deutsch")
+ translation_link("es","en|es","fl_es_sm.gif","Español")
+ translation_link("fr","en|fr","fl_fr_sm.gif","Français")
+ translation_link("it","en|it","fl_it_sm.gif","Italiano")
}
// Else, the page has been translated. Write the back-to-English link flag.
else
{
var orig_url = document.location.href;
orig_url = orig_url.slice(7, orig_url.length);
orig_url = orig_url.slice(orig_url.search("http"), orig_url.length);
if (orig_url.search("&") > -1)
orig_url = orig_url.slice(0, orig_url.search("&"));

var original_link = "<a href='" + orig_url + "' title='Original English'>"
+ "<img src='" + flag_folder_url + "flag_english.gif'" + " width='30' height='20' border='0'>"
+ "</a>";
document.write(to_original_heading + original_link);
// document.write("<br><br>REFERER<br>" + document.location.referer);
};
// Bust out of Google's frame if we're not looking at a translated page.
if (top != self &&
document.location.hostname != "216.239.39.104" &&
document.location.hostname != "216.239.37.104" &&
document.location.hostname != "translate.google.com")

top.location.replace(unescape(window.location.path name));
// SCRIPT ENDS

Reply With Quote
  #2  
Old August 13th, 2005, 10:18 PM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 541 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 2 h 15 m 6 sec
Reputation Power: 3
You want to bust out of google's frame even if it is a translated page?

The conditional tests for the frame ~ top != self
and if is not any of 3 possible locations for a translated page

Assuming you want to bust out no matter what anyway.
Comment out the code
Code:
// Bust out of Google's frame if we're not looking at a translated page.
//if (top != self &&
//document.location.hostname != "216.239.39.104" &&
//document.location.hostname != "216.239.37.104" &&
//document.location.hostname != "translate.google.com")


and try using:
Code:
if (top != self)


This may bust out of your frame too, but it's worth a try.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Frames and translated pages


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway