zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    Command Line Tools for win32
    鼠标快速复制粘帖工具!
    IBM T系列笔记本安装2003未知设备问题!
    拔智齿!痛苦磨难中!
    I am a hero!
    vim学习笔记!
    产生数
    NumPy矩阵运算
    1130:找第一个只出现一次的字符
    小A与小姐姐给气球涂色[dp + 快速幂]
  • 原文地址:https://www.cnblogs.com/zh-xiaoyuan/p/12931150.html
Copyright © 2011-2022 走看看