<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 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  How do I make a TextGeometry multiline? How do I put it inside a square so it wraps like html text does inside a div?(如何制作 TextGeometry 多线?如何将它放在一个正方形内,以便它像 html 文本一样包裹在 div 内?) - IT屋-程序员软件开发技术分享社
                  Scale background image to fit ie8 window(缩放背景图像以适合 ie8 窗口)
                  Safari 5.1 breaks CSS table cell spacing(Safari 5.1 打破 CSS 表格单元格间距)
                  Put in bold part of description in metatag Drupal module(将描述的粗体部分放在元标记 Drupal 模块中)
                  Is it possible to compile Coffeescript code in script tags in html files?(是否可以在 html 文件的脚本标签中编译 Coffeescript 代码?)
                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>