Django下实现:
urls.py:
from django.conf.urls import url from django.contrib import admin from app01 import views urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^index/', views.index), url(r'^pop/', views.pop), ]
app01.views.py
from django.shortcuts import render def index(request): return render(request,'index.html') def pop(request): if request.method == "GET": return render(request, 'pop.html') else: user = request.POST.get('user') #这里可以有数据库操作 return render(request,'pop_response.html',{'user':user})
templates.index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h1 id="i1">无所谓</h1> <a href="#" onclick="popUp('http://www.oldboyedu.com')">点我点我</a> <script> function xxxpopupCallback(text) { document.getElementById('i1').innerHTML = text; } function popUp(url) { window.open( '/pop/', '/pop/' ,"status=1, height:500, 600, toolbar=0, resizeable=0"); } </script> </body> </html>
templates.pop.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form method="post"> {% csrf_token %} <input type="text" name="user"> <input type="submit" value="保存"> </form> </body> </html>
templates.pop_response.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h1>正在关闭</h1> <script> (function () { // 可以调用popup原页面的一个函数 opener.xxxpopupCallback("{{ user }}"); window.close(); })() </script> </body> </html>