<small id='oafee'></small><noframes id='oafee'>

    • <bdo id='oafee'></bdo><ul id='oafee'></ul>
    <tfoot id='oafee'></tfoot>
  • <i id='oafee'><tr id='oafee'><dt id='oafee'><q id='oafee'><span id='oafee'><b id='oafee'><form id='oafee'><ins id='oafee'></ins><ul id='oafee'></ul><sub id='oafee'></sub></form><legend id='oafee'></legend><bdo id='oafee'><pre id='oafee'><center id='oafee'></center></pre></bdo></b><th id='oafee'></th></span></q></dt></tr></i><div id='oafee'><tfoot id='oafee'></tfoot><dl id='oafee'><fieldset id='oafee'></fieldset></dl></div>

        <legend id='oafee'><style id='oafee'><dir id='oafee'><q id='oafee'></q></dir></style></legend>

        有没有办法在一个页面上加载多个谷歌翻译小部件

        时间:2023-09-07

        1. <i id='ly9Sn'><tr id='ly9Sn'><dt id='ly9Sn'><q id='ly9Sn'><span id='ly9Sn'><b id='ly9Sn'><form id='ly9Sn'><ins id='ly9Sn'></ins><ul id='ly9Sn'></ul><sub id='ly9Sn'></sub></form><legend id='ly9Sn'></legend><bdo id='ly9Sn'><pre id='ly9Sn'><center id='ly9Sn'></center></pre></bdo></b><th id='ly9Sn'></th></span></q></dt></tr></i><div id='ly9Sn'><tfoot id='ly9Sn'></tfoot><dl id='ly9Sn'><fieldset id='ly9Sn'></fieldset></dl></div>
                <tbody id='ly9Sn'></tbody>
              <legend id='ly9Sn'><style id='ly9Sn'><dir id='ly9Sn'><q id='ly9Sn'></q></dir></style></legend><tfoot id='ly9Sn'></tfoot>

              <small id='ly9Sn'></small><noframes id='ly9Sn'>

              • <bdo id='ly9Sn'></bdo><ul id='ly9Sn'></ul>
                  本文介绍了有没有办法在一个页面上加载多个谷歌翻译小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  例如,有什么方法可以在侧边栏中加载一个谷歌翻译小部件,在页脚中加载一个.

                  Is there any way possible to load a Google Translate widget in the sidebar and one in the footer, for example.

                  我尝试过的每一种方式都只加载了,因此它们都出现在页面上第一个实例的位置.

                  Every way I've tried has only loaded so that both appear in the location of the first instance on the page.

                  推荐答案

                  经过一番修改后,我觉得有必要解决这个难题!您可以通过查看 jsfiddle 来跳到好的部分:(它现在可以工作,但知道谷歌可能明天就不行了)

                  After a bit of tinkering I kinda felt obligated to solve the puzzle! You can skip to the good part by checking out the jsfiddle: (it works as of now but knowing google it might not tomorrow)

                  http://jsfiddle.net/melfy/15zr6ov0/

                  开始吧:

                  首先加载谷歌翻译并为选择框添加一个侦听器,在您调用正确的元素后它添加到 DOM,但我们需要该更改事件来调用我们将从原始克隆中克隆的选择框的更改让谷歌更新翻译,这会有点混乱,因为我们接管了原型(这通常是不好的做法)

                  First google translate is loaded and adds a listener for a select box it adds to the DOM after you call the right element but we need that change event to call a change for a select box we're going to clone from the original one to get google to update the translation, this gets a bit messy as we over take the prototype (which is usually bad practice)

                  首先添加您的标题元素:

                  Start by adding your header element:

                  <div id="google_translate_element"></div>
                  

                  然后我们添加页脚元素:

                  Then we add our footer element:

                  <div id="google_translate_element2"></div>
                  

                  接下来我们拉入谷歌翻译器

                  Next we pull in the google translator

                  <script type="text/javascript" src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
                  

                  现在我们进入了好的部分:

                  Now we get to the good part:

                  <script type="text/javascript">
                  
                  // store google translate's change event
                  trackChange = null;
                  pageDelayed = 3000;
                  
                  // overwrite prototype to snoop, reset after we find it (keep this right before translate init)
                  Element.prototype._addEventListener = Element.prototype.addEventListener;
                  Element.prototype.addEventListener = function(a,b,c) {
                    reset = false;
                  
                    // filter out first change event
                    if (a == 'change'){
                      trackChange = b;
                      reset = true;
                    }
                  
                    if(c==undefined)
                      c=false;
                  
                    this._addEventListener(a,b,c);
                  
                    if(!this.eventListenerList)
                      this.eventListenerList = {};
                  
                    if(!this.eventListenerList[a])
                      this.eventListenerList[a] = [];
                  
                    this.eventListenerList[a].push({listener:b,useCapture:c});
                  
                    if (reset){
                      Element.prototype.addEventListener = Element.prototype._addEventListener;
                    }
                  };
                  
                  
                  function googleTranslateElementInit() {
                    new google.translate.TranslateElement({ pageLanguage: 'en' }, 'google_translate_element');
                  
                    let first = $('#google_translate_element');
                    let second = $('#google_translate_element2');
                  
                    let nowChanging = false;
                  
                    // we need to let it load, since it'll be in footer a small delay shouldn't be a problem
                    setTimeout(function(){
                      select = first.find('select');
                      // lets clone the translate select
                      second.html(first.clone());
                      second.find('select').val(select.val());
                  
                      // add our own event change
                      first.find('select').on('change', function(event){
                        if (nowChanging == false){
                          second.find('select').val($(this).val());
                        }
                        return true;
                      });
                  
                      second.find('select').on('change', function(event){
                        if (nowChanging){
                          return;
                        }
                  
                        nowChanging = true;
                        first.find('select').val($(this).val());
                        trackChange();
                  
                        // give this some timeout incase changing events try to hit each other                    
                        setTimeout(function(){
                          nowChanging = false;
                        }, 1000);
                  
                      });
                    }, pageDelayed);
                  }
                  </script>
                  

                  您可以更改 pageDelayed 变量以更快或更慢地触发,但如果它在您的页脚中,将其延迟更长的时间可能有助于它更有效地工作,具体取决于您的页面加载

                  You can change the pageDelayed variable to trigger quicker or slower but if it's in your footer, bumping it up to delay longer may help it work more efficiently depending on your page load

                  这篇关于有没有办法在一个页面上加载多个谷歌翻译小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用重新定义父方法在 Jquery UI 中扩展小部件 下一篇:UserVoice 等托管服务如何将其内容嵌入其他网站?

                  相关文章

                    <tfoot id='589x2'></tfoot>

                    • <bdo id='589x2'></bdo><ul id='589x2'></ul>
                  1. <i id='589x2'><tr id='589x2'><dt id='589x2'><q id='589x2'><span id='589x2'><b id='589x2'><form id='589x2'><ins id='589x2'></ins><ul id='589x2'></ul><sub id='589x2'></sub></form><legend id='589x2'></legend><bdo id='589x2'><pre id='589x2'><center id='589x2'></center></pre></bdo></b><th id='589x2'></th></span></q></dt></tr></i><div id='589x2'><tfoot id='589x2'></tfoot><dl id='589x2'><fieldset id='589x2'></fieldset></dl></div>
                  2. <legend id='589x2'><style id='589x2'><dir id='589x2'><q id='589x2'></q></dir></style></legend>
                  3. <small id='589x2'></small><noframes id='589x2'>