gpt4 book ai didi

javascript : How to write inside popup window

转载 作者:行者123 更新时间:2023-11-29 15:18:23 25 4
gpt4 key购买 nike

我创建了一个 javascript 程序,我创建了电影对象,我创建了一个名为 myWin 的新窗口,在 myWin 中我创建了另一个名为 actorWin 的窗口。现在,当我单击单击此处以访问 Actor 窗口时,我想在 actorWin 中传递 url(myMovie.actor) 和描述(myMovie.website_actor)。我试过下面的方法,但那是行不通的。谁能建议我如何在 actorWin 弹出窗口中编写。

代码:

<!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>

输出:

/image/xbPIL.jpg

最佳答案

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

初始 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

关于javascript : How to write inside popup window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46519897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com