首页 > 代码库 > js中iframe的用法
js中iframe的用法
最近遇到的项目总是习惯左边一个树,点击每个树的节点右边出现相应的信息,遇到这种情况用iframe还是很简单的,
例如 : 页面文件
1 @section Tree{ 2 <ul id="tree"> 3 </ul> 4 5 } 6 @section Search 7 { 8 } 9 <input id="clickassets" type="hidden" value=http://www.mamicode.com/"@ViewBag.url" />10 <div class="g_tgCenterGrid" data-options="region:‘center‘,border:1" id="dvGrid"> 11 <iframe marginwidth="0" src=http://www.mamicode.com/"@Url.Content("~/System/MachineConfig")" nodeId="00302" style="width: 100%; height: 750px" name="i" id="urlIframe"12 frameborder="0" scrolling="no"></iframe>13 </div>
js文件
1 $.ajax({ 2 dataType: "text", 3 url: TY.Root + "System/MachineConfigInfo?RowId=" + nodeid + "&m_name=" + noidtext, 4 type: "post", 5 success: function (result) { 6 7 if (result != null && result != "") { 8 var da = result.split(","); 9 var me = this;10 $("#dvGrid").html("<iframe marginwidth=‘0‘ src=http://www.mamicode.com/‘MachineConfig?nodeId=" + da[0] + ‘,‘ + da[1] + ‘&RowId=‘ + da[0] + ‘&m_name=‘ + da[1] + "‘ style=‘width: 100%; height: 750px‘ name=‘i‘ id=‘urlIframe‘ frameborder=‘0‘ scrolling=‘no‘></iframe>");11 12 }13 }14 15 });
传递到该页面后,接收iframe传递过来的参数
1 if (location.href.indexOf("?nodeId=") > -1) { 2 var ids = request(‘nodeId‘); 3 var da = ids.split(","); 4 } 5 6 7 8 //获取url的参数 9 function request(strParame) {10 var args = new Object();11 var query = location.search.substring(1);12 13 var pairs = query.split("?"); // Break at ampersand 14 for (var i = 0; i < pairs.length; i++) {15 var pos = pairs[i].indexOf(‘=‘);16 if (pos == -1) continue;17 var argname = pairs[i].substring(0, pos);18 var value = http://www.mamicode.com/pairs[i].substring(pos + 1);19 value =http://www.mamicode.com/ decodeURIComponent(value);20 args[argname] = value;21 }22 return args[strParame];23 }
js中iframe的用法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。