iframe 获取 url 参数
时间: 2023-08-24 08:09:15 浏览: 128
获取url参数
要在iframe中获取URL参数,可以使用以下代码:
```javascript
function requestParameter() {
var paramObj = new Object();
var url = window.location.search; // 获取url中第一个"?"符后的字符串
var paramStr = url.substr(1).split("?")\[1\]; // 获取url中第二个"?"后的字符串
var paramArray = paramStr.split("&");
for (var i = 0; i < paramArray.length; i++) {
paramObj\[paramArray\[i\].split("=")\[0\]\] = (paramArray\[i\].split("=")\[1\]);
}
return paramObj;
}
var param1 = requestParameter()\["param1"\];
var param2 = requestParameter()\["param2"\];
```
这段代码将URL参数解析为一个对象,你可以通过`param1`和`param2`来获取对应的参数值。
#### 引用[.reference_title]
- *1* [获取Layui iframe页面的url参数](https://blog.csdn.net/qq_41829337/article/details/126290625)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [iframes传递参数后获取参数方法(url中传参)](https://blog.csdn.net/Anno_O/article/details/114328120)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文