IOS

实现在app内打开第三方H5页面再回跳

2017-12-12  本文已影响785人  冰Q

最近项目中需要实现一个功能,在app内打开第三方H5页面,再回跳到app,发现被自己坑了一波。有两种方式:

// 在app页面内生成iframe
var iframe = $('<iframe id="iframe_pop" style="width: 100%;height: 100%;position: fixed;top:0;left:0;z-index: 1000;" frameborder=0 marginheight=0 marginwidth=0 scrolling=no src=SRC></iframe>');
$("body").append(iframe);

// 在iframe内插入表单并提交
window.frames["iframe_pop"].contentWindow.document.body.innerHTML = "表单字符串";
$(window.frames["iframe_pop"].contentWindow.document.body).find("form").submit();

// 在我方的第三方页面(即相对本地资源的服务器资源)
// targetWindow.postMessage(data, targetOrigin)
window.parent.postMessage(data, '*');

// 在app页面内监听message
window.addEventListener('message',function(e){
    $(window.frames["iframe_pop"]).remove();
        var result = e.data;
},false);
上一篇 下一篇

猜你喜欢

热点阅读