[轉]js獲取iframe經過url傳遞的參數

1.前言html

獲取iframe的url路徑:window.parent.document.getElementById("your-iframe-id").contentWindow.location.search; //須要iframe的IDbash

2.代碼url

根據參數名稱經過正則獲取參數值code

function geturl(name) {
            var reg = new RegExp("[^\?&]?" + encodeURI(name) + "=[^&]+");
            var arr = window.parent.document.getElementById("Ateon-SetParent-iframe").contentWindow.location.search.match(reg);
            if (arr != null) {
                return decodeURI(arr[0].substring(arr[0].search("=") + 1));
            }
            return "";
        }

3 參考htm

1.https://www.cnblogs.com/kcjm/p/7060073.htmlblog

相關文章
相關標籤/搜索