iframe.html 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>layer iframe 示例</title>
  6. <meta name="renderer" content="webkit">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  9. <link rel="stylesheet" href="../../../../start/layui/css/layui.css" media="all">
  10. <style>
  11. body{padding:10px; font-size:14px; background:#fff; width:95%; margin:0 auto; font-size:14px; line-height:20px; overflow:hidden;}
  12. p{margin-bottom:10px;}
  13. input{border:1px solid #999; padding:5px 10px; margin:0 10px 10px 0;}
  14. </style>
  15. </head>
  16. <body>
  17. <input class="layui-input" placeholder="标记" id="LAY_mark">
  18. <div class="layui-btn-container">
  19. <button class="layui-btn layui-btn-primary" data-type="auto">让层自适应iframe</button>
  20. <button class="layui-btn layui-btn-primary" data-type="parentPopup">在父层弹出一个层</button>
  21. <button class="layui-btn layui-btn-primary" data-type="setParent">给父页面传值</button>
  22. <button class="layui-btn layui-btn-primary" data-type="close">在内部关闭iframe</button>
  23. </div>
  24. <script src="../../../../start/layui/layui.js"></script>
  25. <script>
  26. layui.use('layer', function(){
  27. var $ = layui.$
  28. ,layer = layui.layer
  29. ,index = parent.layer.getFrameIndex(window.name); //获取窗口索引
  30. var active = {
  31. //让层自适应iframe
  32. auto: function(){
  33. $('body').append('插入很多酱油。插入很多酱油。插入很多酱油。插入很多酱油。插入很多酱油。插入很多酱油。插入很多酱油。');
  34. parent.layer.iframeAuto(index);
  35. }
  36. //在父层弹出一个层
  37. ,parentPopup: function(){
  38. parent.layer.msg('Hi, man', {shade: 0.3})
  39. }
  40. //给父页面传值
  41. ,setParent: function(){
  42. var id = '#LAY_layer_iframe_demo'
  43. ,mark = $('#LAY_mark')
  44. ,val = mark.val();
  45. if(val === ''){
  46. mark.focus();
  47. parent.layer.msg('请填写标记');
  48. return true;
  49. }
  50. parent.layer.msg('您将标记 [ ' +val + ' ] 成功传送给了父窗口');
  51. parent.layui.$(id).text('我被改变了');
  52. parent.layer.tips('Look here', id, {
  53. time: 5000
  54. });
  55. parent.layer.close(index);
  56. }
  57. //在内部关闭iframe
  58. ,close: function(set){
  59. parent.layer.close(index);
  60. }
  61. }
  62. $('.layui-btn-container .layui-btn').on('click', function(){
  63. var othis = $(this)
  64. ,type = othis.data('type');
  65. active[type] && active[type].call(this);
  66. });
  67. });
  68. </script>
  69. </body>
  70. </html>