html中嵌套iframe页面

有时候需要把其他地方的页面嵌套到当前的的网站的某个模块中,就可以使用iframe嵌套
1、不需要登录其他网站的直接嵌套
新建html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>百度</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        html, body {
            height: 100%;
            width: 100%;
            overflow: hidden;
        }

        iframe {
            border: 0;
        }
    </style>
</head>
<body>
<iframe id="mainContent" width="100%" height="100%"></iframe>
</body>
<script>
 
    var mainContent = document.getElementById('mainContent');
    mainContent.src = "http:baidu.com.cn"//嵌套网址

</script>
</html>

2、需要登录其他网址才可以获取嵌套页面
新建html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        html,body{
            height: 100%;
            width: 100%;
            overflow: hidden;
        }
        iframe{
            border: 0;
        }
    </style>
</head>
<body>
    <iframe id="mainContent" width="100%" height="100%"></iframe>
</body>
<script>
    window.parent.Ext.onReady(function(){//因为单独打开窗口,所以这里引用了自己框架的方法,使得  Ext.data.JsonP.request这个方法可以调用
        var Ext = window.parent.Ext ;
        Ext.data.JsonP.request({
            url: 'url',//登录网站
            async: false,
            params: {
                RF_Login_Username:"ordinary",
                RF_Login_Password:123456//用户名和密码
            },
            callbackKey: "callback",
            callbackName: "callback",
            success:function(d){
                var mainContent = document.getElementById('mainContent');
                mainContent.src = "http:url"//嵌套页面网址
            },
            callBack:function(d){
            },
            failure: function (d) {
                alert('请求失败,请关闭窗口后重新打开!');
            }
        });
    })



</script>
</html>
你可以使用Vue Router来实现在Vue应用嵌套HTML页面,而不使用iframe。以下是一个简单的示例: 首先,你需要安装Vue Router: ``` npm install vue-router ``` 然后,在你的Vue应用的入口文件(通常是`main.js`),导入Vue Router并配置路由: ```javascript import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter) const routes = [ { path: '/page1', name: 'Page1', component: () => import('./components/Page1.vue') }, { path: '/page2', name: 'Page2', component: () => import('./components/Page2.vue') }, // 其他页面路由配置... ] const router = new VueRouter({ mode: 'history', routes }) new Vue({ router, render: h => h(App) }).$mount('#app') ``` 在上面的代码,我们通过`import`语句引入了两个组件`Page1.vue`和`Page2.vue`,并将它们分别与路由路径`/page1`和`/page2`关联起来。 接下来,在你的Vue组件,可以使用`<router-view>`标签来渲染嵌套HTML页面。例如,在一个名为`App.vue`的组件: ```vue <template> <div> <h1>My App</h1> <router-view></router-view> </div> </template> <script> export default { name: 'App', } </script> ``` 最后,在`Page1.vue`和`Page2.vue`组件,你可以编写嵌套HTML代码: ```vue <template> <div> <h2>Page 1</h2> <!-- 嵌套HTML代码 --> </div> </template> <script> export default { name: 'Page1', } </script> ``` 这样,当用户访问`/page1`时,Vue Router会将`Page1.vue`组件渲染到`<router-view>`标签,从而实现在Vue应用嵌套HTML页面的效果。 希望对你有所帮助!如有任何问题,请随时向我提问。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值