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


1.前言

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

2.代碼

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

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 參考

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM