|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Frames and translated pages |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|