好的,我有一个页面,在这个页面上我有一个iframe.我需要做的是在iframe页面上,找出主页面的URL是什么.
我已经搜索过,我知道如果我的iframe页面位于不同的域上,这是不可能的,因为这是跨站点脚本.但是我读过的每个地方都说如果iframe页面和父页面在同一个域中,那么如果我这样做,它应该可以工作:
parent.document.location
Run Code Online (Sandbox Code Playgroud)
parent.window.document.location
Run Code Online (Sandbox Code Playgroud)
parent.window.location
Run Code Online (Sandbox Code Playgroud)
parent.document.location.href
Run Code Online (Sandbox Code Playgroud)
...或其他类似的组合,因为似乎有多种方法来获得相同的信息.
不管怎么说,这就是问题所在.我的iframe与主页面位于同一个域中,但它不在同一个SUB域中.所以我举个例子
http:// www.mysite.com/pageA.html
然后我的iframe网址是
http:// qa-www.mysite.com/pageB.html
当我尝试从pageB.html
(iframe页面)获取URL时,我不断收到相同的访问被拒绝错误.所以看起来甚至子域都算作跨站点脚本,这是正确的,还是我做错了什么?
iframe中的网站不在同一个域中,但两者都是我的,我想iframe
在父网站之间进行通信.可能吗?
我正在开发一个本地研究工具,要求我关闭Firefox的相同原始策略(在脚本访问方面,我并不真正关心跨域请求).
更具体地说,我希望主机域中的脚本能够访问页面中嵌入的任何iframe中的任意元素,而不管其域名是什么.
我知道之前的Q&As提到了CORS FF扩展,但这不是我需要的,因为它只允许CORS,但不允许脚本访问.
如果它不能轻易完成,我也很感激任何见解,指出我可以修改以禁用SOP的FF src代码的特定部分,以便我可以重新编译FF.
出于开发目的,我需要在我的机器上的Safari(在Windows上)禁用同源策略.
在Chrome中,可以通过使用标志启动来完成此操作--disable-web-security
.Safari中是否有等效的标志或隐藏设置?
window.popup = window.open($(this).attr('href'), 'Ad', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0');
$(window.popup).onload = function()
{
alert("Popup has loaded a page");
};
Run Code Online (Sandbox Code Playgroud)
这在我尝试过的任何浏览器中都不起作用(IE,Firefox,Chrome).如何检测窗口中何时加载页面(如iframe onload)?
Chrome允许我们禁用相同的原始策略,因此我们可以测试跨源请求.我想知道是否有可能在IE中做同样的事情
我zooming="true"
在标签内添加了但是当页面加载时我无法缩放以增加或减少视图.我还设置webkitallowfullscreen mozallowfullscreen allowfullscreen
缩放页面以适应设备屏幕但没有任何改变,页面仍然被剪切.
为了更好地解释这个概念,我采用Android
原生应用程序.现在,如果您想从Web加载页面,则使用a WebView
,结果就像使用iframe
on一样Ionic
.但在Android上,事情变得更简单:
webview.getSettings().setBuiltInZoomControls(true);
Run Code Online (Sandbox Code Playgroud)
启用捏合缩放,和
webview.getSettings().setUseWideViewPort(true);
Run Code Online (Sandbox Code Playgroud)
根据(移动)屏幕的大小来适应和缩放网页.现在,使用Windows 10
它我不可能建立native iOS apps
所以我必须依靠cross-platform development
.
这里是我的detail-page
:
html
:
<ion-content>
<iframe sandbox class="link" frameborder="0" [src]="webPage()" zooming="true" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</ion-content>
Run Code Online (Sandbox Code Playgroud)
scss
:
detail-page {
.scroll-content{
padding: 0px ;
}
::-webkit-scrollbar,
*::-webkit-scrollbar {
display: none;
}
iframe.link {
width: 100%;
height: 100%;
max-width: 100%;
max-height: 100%;
}
}
Run Code Online (Sandbox Code Playgroud)
ts
:
webPage() {
return this.sanitizer.bypassSecurityTrustResourceUrl(this.entry.getElementsByTagName('link')[0].textContent);
} …
Run Code Online (Sandbox Code Playgroud) 编辑:新标题.我正在寻找的是iframe中元素的document.querySelector.
我做了很多谷歌搜索的答案,最后我很难过.
我正在尝试在iframe内部进行查询.我正在构建在Selenium中使用的字符串选择器,通常我只是使用Firebug检查元素,并使用document.querySelectorAll("theStringIBuid");
但它不适用于iframe中的元素.我已经尝试了以下所有内容在"page-iframe"iframe中获取元素"radiobutton1".
var elem1 = ".page-iframe";
console.log(elem1);
var elem2 = ".radiobutton1";
console.log(elem2);
document.querySelectorAll(elem1+elem2+"");
document.querySelectorAll('.page-iframe').contentWindow.document.body.querySelectorAll('.radiobutton1')
document.getElementById('.page-iframe').contentWindow.document.body.innerHTML;
[].forEach.call( document.querySelectorAll('.page-iframe'),
function fn(elem){
console.log(elem.contentWindow.document.body.querySelectorAll('.radiobutton1')); });
var contentWindow = document.getElementById('.page-iframe').contentWindow
var contentWindow = document.querySelectorAll('.page-iframe')
var contentWindow = document.querySelectorAll('.page-iframe')[0].contentWindow
Run Code Online (Sandbox Code Playgroud)
谢谢-
当用户打印时,我的服务器生成PDF,我这样做是为了显示PDF的打印对话框.
$('<iframe type="application/pdf"></iframe>').attr('src', url).load(function() {
var iframe = this;
setTimeout(function() { //Chrome PDF viewer shows "Loading..." forever otherwise
iframe.contentWindow.print();
$(iframe).remove(); //gc
}, 50);
}).appendTo('body');
Run Code Online (Sandbox Code Playgroud)
但现在我在S3上托管PDF.我明白了
Uncaught SecurityError: Blocked a frame with origin "https://localhost" from
accessing a frame with origin "https://my-bucket.s3.amazonaws.com".
Protocols, domains, and ports must match.
Run Code Online (Sandbox Code Playgroud)
我认为我需要添加CORS头.
我有
Access-Control-Allow-Methods: GET, HEAD
Access-Control-Allow-Origin: *
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
javascript ×6
iframe ×5
html ×3
ajax ×2
cors ×2
cross-domain ×2
firefox ×2
angular ×1
ionic2 ×1
popup ×1
safari ×1
security ×1
websecurity ×1