简体   繁体   English

从iframe打开页面到新窗口/标签页

[英]open a page to new window/tab from iframe

I have a page with an iFrame on it. 我有一个带有iFrame的页面。 On the page in the frame I have a button. 在框架的页面上,我有一个按钮。

What I want is that if the user clicks on the button, another page is opened in it's own new window or tab. 我想要的是,如果用户单击该按钮,则会在其自己的新窗口或选项卡中打开另一个页面。 This functionality is to show the user a print friendly page. 此功能是为了向用户显示易于打印的页面。

How can I do this? 我怎样才能做到这一点?

This is how I now try it: 这就是我现在尝试的方式:

Dim sb2 As New StringBuilder
sb2.Append("window.open('")
sb2.Append(sb.ToString)
sb2.Append("','NewPFWindow','menubar=1,toolbar=1,scrollbars=1,resizable=1,sandbox=""allow-same-origin allow-forms""')")

ClientScript.RegisterClientScriptBlock(Me.GetType, "si2", sb2.ToString, True)

sb holds the page like "mypage.aspx" 某人拥有“ mypage.aspx”之类的页面

Another option is to resize the iFrame so the whole page will fit. 另一个选择是调整iFrame的大小,以便适合整个页面。 Is that possible from code-behind? 从代码后面可以做到吗?

rg. rg。 Eric 埃里克

Just provide a target that has not been named on your site yet, most people will use _blank for that 只需提供尚未在您的网站上命名的target ,大多数人会使用_blank

Ie

<a href="desiredLocationUrl...." target="_blank"> link text </a>

or if you want to tie that to another click-event somewhere else: 或者,如果您要将其与其他位置的其他点击事件相关联:

window.open('desiredLocationUrl....', "_blank"); 

Btw. 顺便说一句。 it does not matter if that link is inside an iframe ;) 该链接是否位于iframe中都没有关系;)

found it. 找到了。

Apparently Chrome uses an undocumented feature. 显然,Chrome使用了未记录的功能。

The frame that is trying to put the new page in it's own window or tab, needs an extra option in the sandbox property called "Allow-popup'. 试图将新页面放在其自己的窗口或选项卡中的框架在沙盒属性中需要一个名为“ Allow-popup”的额外选项。

This is not documented on the w3schools.com website. w3schools.com网站上未对此进行记录。

So by adding this to the sandbox property, you allow the browser to create new window/tab. 因此,通过将其添加到沙箱属性中,可以允许浏览器创建新的窗口/选项卡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM