Javascript 让这个谷歌翻译书签在iframe中运行?
我从中找到了这个GoogleTranslateBookmarklet,我想知道是否有可能在同一个页面的iframe中运行此代码,而不是在新窗口中运行Javascript 让这个谷歌翻译书签在iframe中运行?,javascript,google-translate,bookmarklet,Javascript,Google Translate,Bookmarklet,我从中找到了这个GoogleTranslateBookmarklet,我想知道是否有可能在同一个页面的iframe中运行此代码,而不是在新窗口中运行 javascript: var t = ((window.getSelection && window.getSelection()) || (document.getSelection && document.getSelection()) || (document.selection && doc
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);
不,不可能。
谷歌之所以不可能做到这一点,是因为他们没有在您提供的脚本中包含的url中包含标题,这对于在iframe中显示请求的url内容至关重要
您可以在此处查看一个示例:
您可以在控制台中注意到一条消息,由于缺少标头,请求被拒绝