iframe表单跨域访问

来源:互联网 发布:Green VPN网络加速器 编辑:程序博客网 时间:2024/05/23 11:57

<%@page language="java"  pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title></title>
<script src="jquery-1.8.2.min.js" type="text/javascript"></script>
</head>
<body>
<input type="hidden" id="username" value="${param.username}"/>
<input type="hidden" id="password" value="${param.password}"/>
<input type="hidden" id="backurl" value="http://open.sylai.com/oauth2/auth?client_id=hongware&redirect_uri=http://localhost:8080/wd_callback&response_type=code&scope=user,weixin,wd"/>
<input type="hidden" id="client_id" value="hongware"/>
</body>
</html>
<script type="text/javascript">
 $(function(){  
    smal_send();
 });
 function smal_send(){

//取值
     var user = $("#username").val();
     var pass = $("#password").val();
     var backurl = $("#backurl").val();
  var client_id=$('#client_id').val();
 //创建一个form表单
     var form =$("<form action='http://api.sylai.com/v1/login' method='post'>" +
             "<input type='hidden' name='username' value=''/> " +
             "<input type='hidden' name='password' value=''/> " +
             "<input type='hidden' name='client_id' value=''/> " +
             "</form> ");

//删除id=“SML”的元素
     $( "#SMAL" ).remove();

//向每个匹配元素内部插入内容
     $( "body").append("<iframe id='SMAL' name='SMAL' src='http://api.sylai.com/v1/logout'></iframe>");

//执行次函数
     (function(){

//查找匹配元素内部所有的子节点(包括文本节点),如果元素是一个iframe,则查找文档内容   往一个空框架中加些内容
         $( "#SMAL" ).contents().find('body').html(form);
         $( "#SMAL" ).contents().find("form input[name='username']").val(user);
         $( "#SMAL" ).contents().find("form input[name='password']").val(pass);
         $( "#SMAL" ).contents().find("form input[name='client_id']").val(client_id);
         $( "#SMAL" ).contents().find('form').submit();
 
     }());

//延迟100毫秒之后执行函数
     setTimeout(function(){
         window.location.href=backurl;
 
     },100)
 
 }
</script>

0 0
原创粉丝点击