[英]How to cause an IFrame link to open into a new window?
我有一个使用WP构建并使用SSL的网站。 在我网站的一个页面上,我已将iframe调用添加到另一个http网站。
这是我的iframe电话:
<div class="embed-responsive embed-responsive-16by9">
<iframe src="//childwebsite.com/" target="_blank"></iframe>
</div>
iframe正确显示。 现在,当您单击iframe中的任何内容时,Chrome会显示一条消息,提示您
混合内容:“ https://parentwebsite.com ”上的页面已通过HTTPS加载,但请求了不安全的资源“ http://childwebsite.com ”。 该请求已被阻止; 内容必须通过HTTPS提供。
我正在寻找的是用户在iframe中单击,在浏览器中打开新标签并让用户重定向到子网站上的特定网站。
我尝试将target =“ _ blank”添加到iframe,但是没有用。
我也添加了以下JS,但没有用
//pass the iframe to this iframe getting function
function iframeRef( frameRef ) {
return frameRef.contentWindow ? frameRef.contentWindow.document : frameRef.contentDocument
}
//Get Iframe
var inside = iframeRef( document.getElementById('smugmugGallery') );
//Get all links
var links = inside.getElementsByTagName('input');
//Loop throught links and set their attributes
for (var i = 0 ; i<links.length ; i++){
links[i].setAttribute('target','_blank');
}
任何帮助将不胜感激。
您在这里有两个问题。 SSL问题和跨域问题。
您的SSL问题只能通过通过SSL提供iframed内容或通过非SSL服务提供父页面来解决。 这将删除您看到的安全警报。
如果内容来自另一个域,则无法断言对iframed内容的控制,至少出于跨浏览器的目的,这至少不容易。
在Mozilla开发人员网站上:
试图访问框架内容的脚本应遵循同源策略,并且如果另一个窗口对象是从其他域加载的,则不能访问该窗口对象的大多数属性。 这也适用于试图访问其父窗口的框架内的脚本。 仍然可以使用window.postMessage实现跨域通信。
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#Scripting
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.