使用iframe框架后的页面,执行跳转命令,目标页面内嵌至iframe的子页面的解决方法

问题描述:

        在做项目的过程中,需要完成修改密码后重新登录的功能,但是前端页面使用了IFrame的框架,修改页面内嵌在的index.html中,

重新登录的页面就内嵌到原来的页面中。

问题如图所示:

 

修改密码成功后:

 

出现问题,修改密码页面跳转到的登录页面内置到了子页面中

 登录后出现了如下页面:

 前端使用的是AngularJs,后台使用的springSecurity做的安全控制

原来代码:

password.html

	     
 <a data-toggle="modal" class="btn btn-danger" 
   ng-click="alterPassword(oldPassword,newPassword,password)">提交修改</a>

 

Service.js

//修改密码
	this.alterPassword=function(oldPassword,newPassword){
		return $http.get('../teacher/alterPassword.do?oldPassword='+oldPassword+'&newPassword='+newPassword);
	}

Controller.js

	//修改用户密码
	$scope.alterPassword=function(oldPassword,newPassword,password){
		if(newPassword!=password){
			alert("两次密码输入的不一致!");
			return;
		}
		teacherService.alterPassword(oldPassword,newPassword).success(
				function(response){
					alert(response.message);
					//重新查询 
					location.href="../logout";
		   
		     
				}
		); 
	}

 

修改后代码:

	//修改用户密码
	$scope.alterPassword=function(oldPassword,newPassword,password){
		if(newPassword!=password){
			alert("两次密码输入的不一致!");
			return;
		}
		teacherService.alterPassword(oldPassword,newPassword).success(
				function(response){
					alert(response.message);
					//重新查询 
		        	/*location.href="../logout";*/
		        	windows.parent.location.href="../logout";

		        	
				}
		); 
	}

修改后,index.html的(主页面)直接跳转至的login.html页面

问题完美解决。

 

解决方法有两个:
(1)在<a> </a>标签中跳转,设置标签的目标属性为_parent;

<a target="_parent" href="../logout">安全退出</a>

(2)在js中使用window.location.href跳转,让父页面跟着一起跳转,即在window.location.href = url改为window.parent.location.href = url;(window可省略)

我根据项目采用的是第二种

 

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
iframe页面内嵌跳转Vue,可以通过以下步骤实现: 1. 首先,在父页面引入Vue.js和Vue Router,并创建一个Vue实例。 2. 在父页面创建一个iframe元素,并设置src属性为要内嵌页面的URL。 3. 在页面同样引入Vue.js和Vue Router,并创建一个Vue实例。 4. 在页面的Vue实例配置路由,定义路由表和对应的组件。 5. 在页面的Vue实例使用<router-view>标签来显示路由对应的组件。 6. 在父页面的Vue实例使用Vue Router的push方法来进行内嵌跳转,即改变iframe的src属性为目标路由的URL。 下面是一个简单的示例代码: 父页面(index.html): ```html <!DOCTYPE html> <html> <head> <title>Parent Page</title> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script> </head> <body> <div id="app"> <iframe :src="iframeSrc"></iframe> <button @click="navigateToChildPage">Go to Child Page</button> </div> <script> const router = new VueRouter({ routes: [ { path: '/child', component: ChildPage } ] }); const app = new Vue({ el: '#app', data: { iframeSrc: 'child.html' }, methods: { navigateToChildPage() { this.iframeSrc = '/child'; } }, router }); </script> </body> </html> ``` 页面(child.html): ```html <!DOCTYPE html> <html> <head> <title>Child Page</title> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script> </head> <body> <div id="app"> <router-view></router-view> </div> <script> const ChildPage = { template: '<div>Child Page Content</div>' }; const router = new VueRouter({ routes: [ { path: '/', component: ChildPage } ] }); const app = new Vue({ el: '#app', router }); </script> </body> </html> ``` 在这个示例,父页面的按钮点击事件会触发父页面的Vue实例的navigateToChildPage方法,该方法会改变iframe的src属性为页面的URL,从而实现内嵌跳转

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值