<bdo id='RmNiF'></bdo><ul id='RmNiF'></ul>
  • <small id='RmNiF'></small><noframes id='RmNiF'>

  • <legend id='RmNiF'><style id='RmNiF'><dir id='RmNiF'><q id='RmNiF'></q></dir></style></legend>

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

      1. <tfoot id='RmNiF'></tfoot>

        使用不同的用户代理加载 iframe 内容

        Load iframe content with different user agent(使用不同的用户代理加载 iframe 内容)

            <tfoot id='Tff1L'></tfoot>
              <tbody id='Tff1L'></tbody>
          • <small id='Tff1L'></small><noframes id='Tff1L'>

              <bdo id='Tff1L'></bdo><ul id='Tff1L'></ul>

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

                  本文介绍了使用不同的用户代理加载 iframe 内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  是否可以使用不同的用户代理加载 iframe ?为 iframe 使用移动用户代理将有助于我的应用将移动网站显示为悬停弹出窗口.

                  Is it possible to load an iframe with different user agent ?? Using a mobile user agent for an iframe will help my app to show mobile sites as hover popup.

                  例如,只有当用户代理来自移动端时,Google 才会显示移动搜索结果页面.

                  For example, Google shows the mobile search results page only if the user agent is from a mobile one.

                  是否有任何替代解决方案,或者这个想法是否涉及任何安全风险??

                  Is there any alternate solutions or is there any security risks involved in this idea ??

                  推荐答案

                  首先,你必须创建一个函数来改变用户代理字符串:

                  First of all, you must create a function to change the user agent string:

                  function setUserAgent(window, userAgent) {
                    if (window.navigator.userAgent != userAgent) {
                      var userAgentProp = {
                        get: function() {
                          return userAgent;
                        }
                      };
                      try {
                        Object.defineProperty(window.navigator, 'userAgent', userAgentProp);
                      } catch (e) {
                        window.navigator = Object.create(navigator, {
                          userAgent: userAgentProp
                        });
                      }
                    }
                  }
                  

                  那么你需要定位iframe元素:

                  Then you need to target the iframe element:

                  setUserAgent(
                      document.querySelector('iframe').contentWindow, 
                      'Aakash Chakravarthy Mobile Agent'
                  );
                  

                  您还可以为 iframe 设置一个 ID,并以该 ID 而非页面上的所有 iframe 元素为目标.

                  You may also set an ID to the iframe and target the ID instead of all iframe elements on the page.

                  这篇关于使用不同的用户代理加载 iframe 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Plot data in website from multiple csv file(从多个 csv 文件中绘制网站中的数据)
                  Content Service for Google Apps Script returning HTML instead of JSON(返回 HTML 而不是 JSON 的 Google Apps 脚本的内容服务)
                  Open page in new window without popup blocking(在新窗口中打开页面而不阻止弹出窗口)
                  Javascript Confirm popup Yes, No button instead of OK and Cancel(Javascript 确认弹出窗口是,否按钮而不是确定和取消)
                  Opensource/free HTML5/CSS3/JavaScript IDE?(开源/免费 HTML5/CSS3/JavaScript IDE?)
                  jump to CSS selector in a css file from the HTML file in Vim using a single keystroke(使用单次击键从 Vim 中的 HTML 文件跳转到 CSS 文件中的 CSS 选择器)
                1. <legend id='BEaHz'><style id='BEaHz'><dir id='BEaHz'><q id='BEaHz'></q></dir></style></legend>

                      <tfoot id='BEaHz'></tfoot>

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

                            <bdo id='BEaHz'></bdo><ul id='BEaHz'></ul>