我想制作一个关于HTML/JS 同源政策的社区维基,希望能帮助任何人搜索这个主题.这是SO上搜索次数最多的主题之一,没有统一的wiki,所以我去:)
相同的源策略可防止从一个源加载的文档或脚本从另一个源获取或设置文档的属性.此政策可以追溯到Netscape Navigator 2.0.
请保持示例详细,最好还链接您的来源.
在我们的应用程序中,我们解析一个网页并将其加载到iFrame中的另一个页面中.加载页面中的所有元素都有其tokenid-s.我需要通过那些tokenid-s选择元素.意思是 - 我点击主页面上的一个元素,然后在iFrame的页面中选择相应的元素.在jQuery的帮助下,我按以下方式进行:
function selectElement(token) {
$('[tokenid=' + token + ']').addClass('border');
}
Run Code Online (Sandbox Code Playgroud)
但是使用此功能,我只能选择当前页面中的元素,而不能选择iFrame中的元素.有谁能告诉我如何在加载的iFrame中选择元素?
谢谢.
如何使用jQuery访问iframe的内容?我试过这样做,但它不起作用:
iframe内容: <div id="myContent"></div>
jQuery的: $("#myiframe").find("#myContent")
我怎样才能访问myContent?
与 jquery/javascript 类似:访问iframe的内容,但接受的答案不是我想要的.
我想知道是否有可能通过用户的IP刮取外部(跨域)页面?
对于购物比较网站,我需要抓一个e-com网站的页面,但是来自服务器的几个请求会让我被禁止,所以我正在寻找方法进行客户端抓取 - 也就是说,请求来自用户的页面IP并发送到服务器进行处理.
如果我打开一个这样的对话框:
$('<iframe id="externalSite" class="externalSite" src="http://www.example.com" />').dialog({
autoOpen: true,
width: 800,
height: 500,
modal: true,
resizable: true
})
Run Code Online (Sandbox Code Playgroud)
如何使用iframe关闭对话框?
我是printThis的作者,这是一个用于打印的jquery插件.
https://github.com/jasonday/printThis
我有一个用户提出了一个问题,我一直无法破解,不幸的是,我无法分享页面(隐私问题).
在用户的网站上,问题出现在IE的某些页面上,而不是其他页面上.打印失败,因为iframe仍然是空的.
IE中的错误在jQuery中:
contents: function (a) {
return f.nodeName(a,
"iframe") ? a.contentDocument || a.contentWindow.document : f.makeArray(a.childNodes)
}
Run Code Online (Sandbox Code Playgroud)
使用日志记录,我能够确定它在此行中失败:
var $doc = $("#" + strFrameName).contents();
Run Code Online (Sandbox Code Playgroud)
但同样,这只发生在某些页面上,我无法在该用户网站之外的任何实例中重新创建.
我的问题:这里有更好的方法吗?或一种使$doc物体更具防弹性的方法?
// -----------------------------------------------------------------------
// printThis v1.1
// Printing plug-in for jQuery
//
// Resources (based on) :
// jPrintArea: http://plugins.jquery.com/project/jPrintArea
// jqPrint: https://github.com/permanenttourist/jquery.jqprint
// Ben Nadal: http://www.bennadel.com/blog/1591-Ask-Ben-Print-Part-Of-A-Web-Page-With-jQuery.htm
//
// Dual licensed under the MIT and GPL licenses:
// http://www.opensource.org/licenses/mit-license.php
// http://www.gnu.org/licenses/gpl.html
//
// (c) Jason Day 2012
//
// Usage:
// …Run Code Online (Sandbox Code Playgroud) 我通过以下方式动态创建IFRAME:
var wrapUpIframe = document.createElement("iframe");
wrapUpIframe.id = 'WrapUpDialog3';
wrapUpIframe.src = 'WrapUpDialog.html';
document.body.appendChild(wrapUpIframe);
Run Code Online (Sandbox Code Playgroud)
在动态创作之后,我document.domain被缩短Servername.dc.com到只有dc.com,
但是当我尝试访问时,contentWindow我得到了一个Access被拒绝的错误:
document.getElementById("WrapUpDialog3").contentWindow.SomeFunction();
Run Code Online (Sandbox Code Playgroud)
注意:当我在HTML中静态定义IFRAME时,它可以正常工作.
我还试图document.domain通过以下方式更改我的IFRAME :
WrapUpDialog3.document.domain = dc.com;
Run Code Online (Sandbox Code Playgroud)
我检查了两个document.domain和我的IFRAME域,它们都是相同的.
我能做什么?
我正在使用IE9.
我想点击基于我父页面中的类选择器在iframe中打开的网页上的按钮.
我试过这个:
$.each($('.classname'), function(i, el){
setTimeout(function(){
$(el).trigger('click');
},30000 + ( i * 30000 ));
});
Run Code Online (Sandbox Code Playgroud)
但没有成功.我怎样才能实现这一目标?
反正有没有得到iframe加载页面的源代码?我不想更改任何代码,我只想阅读它.我还需要能够使用javascript/html获得此功能.
嗨,朋友们,我尝试使用 jquery 为 iframe html 元素添加类,但我不能,我不知道如何。你能解释一下这怎么可能做到。我尝试使用查询为 iframe 添加类
$("iframe").addClass("myClass");
Run Code Online (Sandbox Code Playgroud)
它适用于 iframe,但我想在 jquery 的 iframe 元素中添加类,你能帮我解决这个问题吗?