apicloud中的窗口组如何链接外部页面

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了apicloud中的窗口组如何链接外部页面相关的知识,希望对你有一定的参考价值。

参考技术A apiready = function()
var js = "apiready = function()api.openFrame(name: 'B',url: './head/html' ,rect: x: 0,y: 0,w: api.winWidth,h: 64,bounces: false,opaque: false,vScrollBarEnabled: false);";
api.execScript(
name: 'B',
script: js
);

如何从外部窗口检测用户在 iframe 中导航到的 URL?

【中文标题】如何从外部窗口检测用户在 iframe 中导航到的 URL?【英文标题】:How to detect the URL user is navigating to in an iframe from the outer window? 【发布时间】:2014-08-02 16:32:32 【问题描述】:

场景如下:

该页面中有一个页面和一个 iframe。一开始,它们都来自同一个域(起源)。 iframe 可以包含到其他域的链接(或更改 window.location.href 的 javascript)。我想在外部框架中检测,当用户离开 iframe 中的原始域时,将外部页面的 window.location.href 替换为用户导航到的 URL,从而结束原来的 application在外框内运行。

尝试使用 beforeunload 事件,但内部框架的 location.href 没有改变。 iframe DOM 元素的 src 属性在 contentDocument 更改时也不会更改。

我的问题在当前的浏览器实现中是否可以解决,或者您会使用什么方法来获得最接近描述的行为?

【问题讨论】:

可能重复? ***.com/questions/2429045/… 并非如此。我在第一段中提到,当 iframe document.location.href 从内部更改时, src 属性不会更改。因此,'load' 事件和标记为答案的 contentDocument.location.href 没有解决方案,因为 iframe 导航到不同的域。 您是否可以控制初始 iframe 应用程序? 是的。我的脚本最初在外部框架和 iframe 中运行。 【参考方案1】:
    $(document).ready(function () 
                $("#widget").load(function () 
                    var ifr = document.getElementById("widget")
                    var anchors = ifr.contentDocument.getElementsByTagName("a");
                    for (var i in anchors) 
                        anchors[i].setAttribute("onClick", "testUrl()");
                    
                );
            );  
function testUrl()    
    //your code goes here for validating the URLs... 

【讨论】:

以上是关于apicloud中的窗口组如何链接外部页面的主要内容,如果未能解决你的问题,请参考以下文章

通过apicloud实现的混合开发App的Demo

APICloud教程

“H5跨平台APP开发”APICloud从入门到精通

vue-打包为webapp,如何解决应用内跳转外部链接返回导致退出应用

iframe中的弹出窗口如何显示在最外层?

如何从外部窗口检测用户在 iframe 中导航到的 URL?