window.open简单使用

摘要:
窗户。open()方法用于打开新的浏览器窗口或查找命名窗口。DOCTYPE html˃子窗口窗口。开瓶器bar//在子窗口中执行父窗口的功能,然后关闭窗口。close()

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>

window.open简单使用第1张

免责声明:文章转载自《window.open简单使用》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Hive Server2(五)C++学习笔记九顺序容器(二) ForFreeDom 博客园下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

django使用ldap认证

pip3 installdjango-auth-ldap python-ldap urls.py, from app0104 importviews urlpatterns =[ url(r'^admin/', admin.site.urls), url(r'^loginauth/', views.loginauth), url(r...

eclipse&amp;amp;myeclipse 生成jar包后,spring无法扫描到bean定义

问题:eclipse&myeclipse 生成jar包后,spring无法扫描到bean定义 在使用getbean或者扫包时注入bean失败,但在IDE里是可以正常运行的? 原因:导出jar未将目录一起导出。 解决方法:将代码目录一起导出:一定要勾选 Add directory enttries 区别: 代码结构: 未勾选,导出内容为: MET...

Request method 'GET' not supported

Request method 'GET' not supported 错误原因: GET请求不被允许。 解决方法: 1.从客户端入手。假设浏览器中的js用了ajax发起异步请求GET,将GET改为POST。 2.从服务端入手。Controller层的  @RequestMapping( method  =RequestMethod.POST ),将POST...

Redis 中 byte格式 写入、取出

实体类: package com.nf.redisDemo1.entity; import java.io.Serializable; public class News implements Serializable { private long id; private String title; private Str...

Dart: List排序

var list = <Item>[ Item(title: "item 1", isTopping: true), Item(title: "item 2"), Item(title: "item 3", isTopping: true), Item(title: "item 4"), ]; main(List<Str...

Python学习————drf(三)

1 请求和响应 1.1 请求 # 请求对象 # from rest_framework.request import Request def __init__(self, request, parsers=None, authenticators=None, negotiator=None, parser_cont...