• window.open简单使用


    window.open() 方法用于打开一个新的浏览器窗口或查找一个已命名的窗口。

    语法

    window.open(URL,name,specs,replace
     
    使用:
    views.py
    from django.shortcuts import render,redirect,HttpResponse
    
    def index(request):
        return render(request,"index.html")
    
    from .models import  Book
    
    def addbook(request):
        if request.method=="POST":
            title=request.POST.get("title")
            Book.objects.create(title=title)
            return render(request,"pop.html",locals())
        else:
            return render(request,"addbook.html")

    index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>父窗口</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
    
    </head>
    <body>
        <h1>Index</h1>
        <p><button class="add" onclick="foo()">+</button></p>
    
        <p class="book_title"></p>
        <script src="/static/jquery-3.3.1.js"></script>
    
        <script>
            function foo() {
                window.open("/addbook/","","width=400,height=400,top=100,left=200")
            }
    
            function bar(arg) {
                console.log(arg);
                $(".book_title").text(arg)
            }
        </script>
    </body>
    </html>

    addbook.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/jquery-3.3.1.js"></script>
    </head>
    <body>
    
    <form action="" method="post">
        {% csrf_token %}
        书籍:<input type="text" name="title">
        <input type="submit">
    </form>
    
    
    </body>
    </html>

    pop.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>子窗口</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
    
        <script src="/static/jquery-3.3.1.js"></script>
    
    </head>
    <body>
    <script>
        window.opener.bar("{{ title }}");   //子窗口中执行父窗口的函数,然后关闭此窗口
        window.close()
    </script>
    </body>
    </html>

  • 相关阅读:
    福利贴——爬取美女图片的Java爬虫小程序代码
    select多选 multiple的使用
    Android笔记---点击事件的四种写法
    二叉排序树的插入与删除
    hdu 5269 ZYB loves Xor I &amp;&amp; BestCoder Round #44
    linux 下同步异步,堵塞非堵塞的一些想法
    JavaScript编程随笔
    《从零開始学Swift》学习笔记(Day 51)——扩展构造函数
    What&#39;s Wrong With Hue Oozie Editor?
    2015.7个人反思小结以及兴许规划
  • 原文地址:https://www.cnblogs.com/zh-xiaoyuan/p/12931150.html
Copyright © 2020-2023  润新知