一、核心
1、做按钮监听,打开窗口
function foo() { window.open('/add/', '', 'width=400,height=200,top=500, left=300') }
2、执行post请求后,返回一个额外的页面
def add_publish(request): if request.method == "POST": publisher = request.POST.get("publisher") print(publisher) # models.Publish.objects.create(name=publisher) return render(request, "pop.html", {"publish": publisher}) return render(request, "add_publish.html")
3、在这个页面添加 调用父窗口的函数,关闭窗口
<script> window.opener.bar("{{ publish }}"); window.close(); </script>
4、注意主页面的被调用的函数
function bar(data) { console.log(data); $(".my-bar").text(data)