javascript 如何在 iframe 外面显示弹出窗口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6854832/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 22:06:57  来源:igfitidea点击:

How to Show the Pop up in iframe outside?

javascriptiframepopup

提问by Tinoy Jameson

I have one page(say jobs.html) with an iframe loads another page( say joblist.html).There is one another popup(which displays description of job when clicks one title) which is generated with javascript will be load into the page in iframe when it loads. I have to load the popup(job description popup) outside the iframe. Any solution to get the jobs.html page's document body using javascript? or How can i get this popup outside the iframe?

我有一个带有 iframe 的页面(比如jobs.html)加载另一个页面(比如joblist.html)。还有一个用javascript生成的弹出窗口(点击一个标题时显示工作描述)将被加载到页面中在 iframe 加载时。我必须在 iframe 之外加载弹出窗口(工作描述弹出窗口)。使用javascript获取jobs.html页面的文档正文的任何​​解决方案?或者我怎样才能在 iframe 之外获得这个弹出窗口?

Thanks,

谢谢,

采纳答案by Talha Ahmed Khan

You can use the parent function.

您可以使用父函数。

You can define the function of showing the popup on the parent page. not in iFrame and call that function from iFrame.

您可以定义在父页面上显示弹出窗口的功能。不在 iFrame 中并从 iFrame 调用该函数。

Lets suppose you have a function of showing job description in Parent page.

假设您有一个在父页面中显示职位描述的功能。

var showJobDesc = function(jobTitle,jobDesc,...){
    ....
}

now in iFrame call this function like;

现在在 iFrame 中调用这个函数;

parent.showJobDesc(jobTitlem, jobDesc, ...);

By doing this you have no issues for placement/alignment of the Dialog.

通过这样做,您在对话框的放置/对齐方面没有问题。

回答by Nivas

I have to load the popup(job description popup) outside the iframe

我必须在 iframe 之外加载弹出窗口(工作描述弹出窗口)

What do you mean when you say load the popup outside the iframe?

当你说在外面加载弹出窗口是什么意思iframe

If you want to open the other page in a pop up, use window.open

如果要在弹出窗口中打开另一个页面,请使用 window.open

If you want to open the new page replacing the parent's page, use the locationof the window

如果要打开替换父页面的新页面,请使用location窗口的

window.parent.location.href = "newPage.html"

In general, you can refer to the parent window (the window containing the iframe), use window.parent(and therefore the parent window's document as window.parent.document, and any script in the parent window as window.parent.scriptName)

通常,您可以引用父窗口(包含 iframe 的窗口),使用window.parent(因此父窗口的文档为window.parent.document,父窗口中的任何脚本为window.parent.scriptName

回答by Clem

parent.showpopup() throws an access denied error. Kinda makes sense since including an iframe means the developer of the page can control the page it's contained in.

parent.showpopup() 抛出访问被拒绝错误。有点意思,因为包含 iframe 意味着页面的开发人员可以控制它所包含的页面。

回答by sarkiroka

Put the show javascript into container page, and in the iframe just call parent.showpopup().

将显示 javascript 放入容器页面,并在 iframe 中调用parent.showpopup().