-1

I found this google translate bookmarklet from here and I was wondering if it was possible to run this code in an iframe, on the same page, instead of a new window.

javascript: var t = ((window.getSelection && window.getSelection()) || (document.getSelection && document.getSelection()) || (document.selection && document.selection.createRange && document.selection.createRange().text));
var e = (document.charset || document.characterSet);
if (t != '') {
    var url1 = 'http://translate.google.com/?text=' + t + '&hl=en&langpair=auto|sk&tbb=1&ie=' + e;
    window.open(url1, '_blank', "GoogleTranslate", "height=200,width=200")
} else {
    var url2 = 'http://translate.google.com/translate?u=' + encodeURIComponent(location.href) + '&hl=en&langpair=auto|sk&tbb=1&ie=' + e;
    window.open(url2, '_blank', "GoogleTranslate", "height=200,width=200")
};
void(0);
David Devine
  • 27
  • 1
  • 5

1 Answers1

1

NO, it's not possible. Google made it impossible because they did not include the X-Frame-Options header in the urls included in the script you provided, which is essential for displaying the requested url content in an iframe.

You can check an example here: https://jsfiddle.net/5w2tv8fs/ You can notice in console a message that the request is refused because the header is missing.

garry man
  • 445
  • 4
  • 14