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>

  • 相关阅读:
    URLLoader和Loader的区别
    linux的文件permission需要设置,否则会使用as3的urlrequest失败
    基于单个xml的数据库
    require_once()
    AS3里只能让动画听下来,不能让声音停下来的问题
    AS3的百条常用知识收藏
    as3读取xml
    21个营销机构网站设计案例
    Web设计者和开发者必备的27个Chrome插件
    DEDE模块MVC框架基本说明,织梦CMSv5.7MVC开发框架
  • 原文地址:https://www.cnblogs.com/zh-xiaoyuan/p/12931150.html
Copyright © 2011-2022 走看看