javascript:如何在弹出窗口内编写

2023-12-01

我创建了一个 javascript 程序,创建了电影对象,创建了名为 myWin 的新窗口,并在 myWin 内创建了另一个名为 actorWin 的窗口。现在,当我单击“单击此处访问演员窗口”时,我想在 actorWin 中传递 url(myMovie.actor) 和描述(myMovie.website_actor)。我已经尝试过以下方法,但不起作用。谁能建议我如何在 actorWin 弹出窗口中编写。

code:

<!DOCTYPE html>
<html>
<head>

    <title>lab 8</title>
    <script type="text/javascript">

        var myWin = window.open("", "myWin", "height=500, width=500,location,menubar,toolbar,status,resizable");

        function movie(movie_title, website_title, actor, website_actor){
            this.movie_title = movie_title;
            this.website_title = website_title;
            this.actor = actor;
            this.website_actor = website_actor;
        }

        var myMovie = new movie("Before she was Wonder Woman, she was Diana, princess of the Amazons, trained to be an unconquerable warrior. Raised on a sheltered island paradise, Diana meets an American pilot (Chris Pine) who tells her about the massive conflict that's raging in the outside world. Convinced that she can stop the threat, Diana leaves her home for the first time. Fighting alongside men in a war to end all wars, she finally discovers her full powers and true destiny.", 

            "http://www.imdb.com/title/tt0451279/",

            "Gal Gadot is an Israeli actress, singer, martial artist, and model. She was born in Rosh Ha'ayin, Israel, to an Ashkenazi Jewish family. Her parents are Irit, a teacher, and Michael, an engineer, who is a sixth-generation Israeli. She served in the IDF for two years, and won the Miss Israel title in 2004.", 

            "http://www.imdb.com/name/nm2933757/?ref_=tt_cl_t1");

        myWin.document.write(    
            "<script type='text/javascript'>"  
            +    "function movieWindow() {"

            +   "var movieWin = window.open(\"" + myMovie.website_title + "\" , \"movieWin\", \"height=500, width=500,location,menubar,toolbar,status,resizable\");"

            +   "}"

            + "function closeMovie() {"

            +  "movieWin.close()"

            +   "}"

            + "<\/script>");

        myWin.document.write(
        "<script type='text/javascript'>" 
          + "function actorWindow() {"

          +   "var actorWin = window.open(\"''\" , \"actorWin\", \"height=500, width=500,location,menubar,toolbar,status,resizable\");"

          +   "<p style='color: green; font-size: 150%'>  \""+ myMovie.actor + "\" </p>"
          +   "<a  style='color: pink; font-size: 150%' href= \""+myMovie.website_actor +"\"> Click for more info </a> "

          +   "}"

           +    "<\/script>");



        myWin.document.write(

            +"<script type='text/javascript'>"

            +   "<body style='background-image : url(lab8_images/back.png)'>"
            +   "<h1 style= 'text-align: center; color: white; font-family: monospace; font-size: 200%'> What about this movie? </h1>"
            +    '<br/>' + '<br/>' +'<br/>' 

            + "<p style = 'font-family: monospace; font-size: 150%; color: #ffffff; padding: 0px 15px: 0px 15px; text-decoration: none'> \""+ myMovie.movie_title +"\"  </p>"


            +  "<p style = 'font-family: monospace; font-size: 150%; color: #ffffff; text-align:center; text-decoration: none'> <a style='color:white' href = 'javascript: movieWindow()' > CLICK HERE TO ACCESS TO THE MOVIE WINDOW </a><br></p>"

            +   "<p style = 'font-family: monospace;font-size: 150%; color: #ffffff;  text-align: center; text-decoration: none'> <a style='color:white' href = 'javascript: actorWindow()'> CLICK HERE TO ACCESS TO THE ACTOR WINDOW </a><br></p>"

            +   "<p style = 'font-family: monospace; color: white; text-align: center; text-decoration: none; font-size: 150%'> <a style='color:white' href = 'javascript: closeMovie();'> CLICK HERE TO CLOSE THE MOVIE WINDOW </a><br></p>"

            +   "<p style = 'font-family: monospace; color: white; text-align: center; text-decoration: none; font-size: 150%'><a style='color:white' href='javascript:actorWindow.close();'> CLICK HERE TO CLOSE THE ACTOR WINDOW </a><br></p>"

            +   "<p style = 'font-family: monospace; color: white; text-align: center; text-decoration: none; font-size: 150%'><a style='color:white' href='javascript:window.close();'> CLICK HERE TO CLOSE THIS WINDOW </a><br></p>"
            +"  <\/script>"
            );

        </script>

    </head>
    <body background = lab8_images/back.png>

    </body>
    </html>

output:

https://i.stack.imgur.com/xbPIL.jpg


您可以使用window.opener and postMessage()在浏览上下文之间进行通信

初始 HTML

<script>
  let outerWindow = window.open("myWin.html", "_blank");
  window.onmessage = function(e) {
    console.log(e.data);
    // pass data to inner window
    e.source.postMessage(JSON.stringify({a:1, b:2}), document.origin); 
  }
<script>

在“actorWin”HTML

<script>
  window.onmessage = function(e) {
    console.log(e.data); // message from `window` at initial HTML `document`        
  }
  window.opener.opener.postMessage("inner message", document.origin);
</script>

plnkr http://plnkr.co/edit/99cHuMklH9S9d4Rgf73K?p=info

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

javascript:如何在弹出窗口内编写 的相关文章

随机推荐

  • 按时间间隔更新 firebase 条目

    我希望能够以分钟为间隔更新 firebase 条目中的某些值 我不确定如何执行此操作 但已尝试以下操作 var interval setInterval function database ref on value function sna
  • 使用 API 21 更改片段时出现图形错误

    我的 Nexus 5 出现图形问题 当我更改片段时 在新片段出现之前 有一个大正方形 其中包含新片段的一部分 过渡并不顺利 我使用 getSupportFragmentManager 作为片段 使用模拟器 API 21 和其他设备 API
  • 使用 jQuery 将 tr 附加到 thead 结果空白表行

    我正在尝试创建thead with tr 来自 JSON 对象数组 这是必需的 因为 jQuery 数据表需要它 我有以下脚本来做到这一点 但创建tr与空白值 function var json Number 10031 Descripti
  • Mercurial (hg) 更新错误,中止:没有这样的文件或目录

    我无法在我的机器上更新 Mercurial 存储库 当我进行更新时出现以下错误hg up traceback Traceback most recent call last File usr lib python2 7 dist packa
  • 在 CodeIgniter 中重定向 index.php

    我创建了一个 CodeIgniter 应用程序 现在我尝试将带有 index php 的 url 重定向到不带它的 url 我当前的 htaccess 是 RewriteEngine On RewriteBase Removes trail
  • 为什么除非使用临时变量,否则我不能推入 dyn Trait 的 Vec ?

    这是我的代码 use std rc Rc Weak use std cell RefCell trait Trait fn push
  • 尽管已设置标头,但仍不允许 CORS 请求

    我在尝试执行 XHR 请求时收到以下错误 我已经设置了 CORS 响应标头 但显然出现了问题 任何人都可以发现错误吗 XMLHttpRequest 无法加载http domain dev 路径 起源http mobile devAccess
  • 谷歌地图:事件监听器仅记住变量的最终值

    我正在整理一张 Google 地图 其中包含我国各地各个考试中心的位置 它在每个县上绘制一个标记 当您单击县标记时 它会放大并提供该县考试中心的概述 我也在使用 jQuery 来实现这个 问题是这样的 当我绘制县标记并单击它们时 它总是缩放
  • 正则表达式反向引用来匹配不同的值

    我有一个正则表达式 用于匹配以下形式的表达式 val1 operator val2 这个正则表达式看起来像 s a zA Z 0 9 0 9 s ni in gt gt lt lt s a zA Z 0 9 0 9 s 正如你所看到的 这实
  • 如何使用 javascript 更改 JQuery Mobile 按钮图标

    我想要一个根据用户选择更改数据图标类别的按钮 示例按钮为 a href language2 span English span a 我想知道我需要实现什么 JavaScript 代码才能更改自定义定义data icon english fl
  • Castle.Windsor:来自类型化工厂的组件的可选解析

    我有一个带有 Castle Windsor 的 WCF 服务设置 消息到达调度程序 调度程序将它们发送到正确的组件 基本上是一个IHandler
  • Chrome 的 Javascript 控制台:它以对象形式输出什么?

    从 Chrome 中的 javascript 控制台 gt function Person name this name name undefined 此时 根据 Javascript 规范 Person prototype 应该是一个空对
  • 如何并行迭代两个数组? [复制]

    这个问题在这里已经有答案了 我看起来能够并行迭代两个数组 或仅使用一个 for 循环 这是我尝试过的脚本 usr bin env python list1 one two three list2 I II III IV V for word
  • SpriteKit - 创建计时器

    如何创建一个每两秒触发一次的计时器 以便在屏幕上的 HUD 上将分数加一 这是我的 HUD 代码 implementation MyScene int counter BOOL updateLabel SKLabelNode counter
  • 如何在 R 中的直方图上叠加频率多边形?

    以下是我在 R 中使用的代码 使用 RGui 64 位 R 版本 3 3 1 用于绘制数据直方图以及频率多边形 我没有使用ggplot2 如何将频率多边形叠加在直方图之上 这样我就不必制作两个单独的图表 也就是说 我想要绘制直方图 并将频率
  • Firefox 中的 NS_ERROR_INVALID_POINTER 错误是什么?

    在 Firefox 3 5 中测试 JavaScript 代码时 有时会出现以下错误 Component returned failure code 0x80004003 NS ERROR INVALID POINTER 我尝试过谷歌搜索
  • 在自定义策略中获取 Azure AD B2C 应用程序客户端 ID

    您好 使用 B2C 应用程序的客户端 ID 调用自定义策略 我如何在策略中访问它 我认为这将被硬编码到 client id 声明中 但我不认为它是 它仅作为 aud 声明的默认值返回 但我再次在自定义策略中没有看到这一点 Thanks 好吧
  • 选择不同计数 cloudant/couchdb

    我正在使用 Cloudant 启动一个项目 这是一个简单的日志记录系统 因此我可以跟踪应用程序的使用情况 我的文档如下所示 app 应用程序名称 类型 页面视图 登录 ETC 所有者 用户的电子邮件 设备 iphone 安卓 ETC 日期
  • 通过 PHP 导出为 CSV

    假设我有一个数据库 有没有一种方法可以通过 PHP 将数据库中的内容导出到 CSV 文件 和文本文件 如果可能 我个人使用此函数从任何数组创建 CSV 内容 function array2csv array array if count a
  • javascript:如何在弹出窗口内编写

    我创建了一个 javascript 程序 创建了电影对象 创建了名为 myWin 的新窗口 并在 myWin 内创建了另一个名为 actorWin 的窗口 现在 当我单击 单击此处访问演员窗口 时 我想在 actorWin 中传递 url