我正在尝试使用AJAX加载跨域HTML页面,但除非dataType是"jsonp",否则我无法获得响应.但是,使用jsonp,浏览器需要一个脚本mime类型,但是正在接收"text/html".
我的请求代码是:
$.ajax({
type: "GET",
url: "http://saskatchewan.univ-ubs.fr:8080/SASStoredProcess/do?_username=DARTIES3-2012&_password=P@ssw0rd&_program=%2FUtilisateurs%2FDARTIES3-2012%2FMon+dossier%2Fanalyse_dc&annee=2012&ind=V&_action=execute",
dataType: "jsonp",
}).success( function( data ) {
$( 'div.ajax-field' ).html( data );
});
Run Code Online (Sandbox Code Playgroud)
有没有办法避免使用jsonp进行请求?我已经尝试过使用crossDomain参数,但它没有用.
如果没有,是否有任何方式在jsonp中接收html内容?目前,控制台在jsonp回复中说"意外<".
我们的开发和企业站点的框架层次略有不同.
偶尔我需要在不同的框架中引用一个元素.
不幸的是,我不知道该框架在层次结构中的位置.但我确实知道它的身份.
当我不知道确切的结构时,如何找到框架或特定元素?
为了澄清在开发中,它基本上只是一个包含框架的页面.我在框架的上下文中,只是使用window.top.document来获取我想要的文档.
在prod中,嵌套是不同的,window.top.document不起作用,因为它在另外两个框架内.
我无法改变这种结构,它只是我们的应用程序门户的工作方式.
// the iframe of the div I need to access
var iframe = document.getElementsByTagName("iframe")[2];
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
// resize 'player' in the iframe
innerDoc.getElementById('player').width = "1000px";
innerDoc.getElementById('player').height = "650px";
Run Code Online (Sandbox Code Playgroud)
在此脚本的用户脚本中运行:http://www.free-tv-video-online.me/player/sockshare.php?id = 24DA6EAA2561FD60
为什么Chrome出现此错误并导致脚本失败?:
Unsafe JavaScript attempt to access frame with URL http://www.sockshare.com/embed/24DA6EAA2561FD60
from frame with URL http://www.free-tv-video-online.me/player/sockshare.php?id=24DA6EAA2561FD60.
Domains, protocols and ports must match.
Run Code Online (Sandbox Code Playgroud)
(我只是一个基本的Javascript用户)
最后的代码,非常感谢回答者:
// ==UserScript==
// @name Resize
// @include http://www.free-tv-video-online.me/player/sockshare.php*
// @include http://www.sockshare.com/*
// ==/UserScript==
if (!(window.top === window.self)) {
var player …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 iframe 中添加一些 html 元素,以个性化网站。我正在构建一个浏览器扩展,因此不存在跨域问题。我有 iframe:
<iframe id="container" src="http://www.google.com">
<p>Your browser does not support iframes.</p>
</iframe>
Run Code Online (Sandbox Code Playgroud)
然后,当文档已经加载时,我创建元素并插入它......但它永远不会显示在 iframe 中。但我可以获取 iframe 存在的元素并更改其属性。那么,我可以访问这些元素,但不能创建新元素?为什么?
var ifr = document.querySelector("#container");
var ifrDoc = ifr.contentWindow || ifr.contentDocument;
if (ifrDoc.document) ifrDoc = ifrDoc.document;
var elem = ifrDoc.createElement("div");
elem.innerHTML = "Demo Box";
elem.style.width = "50px";
elem.style.height = "50px";
elem.style.position = "absolute";
elem.style.background = "red";
ifrDoc.body.appendChild(elem);
Run Code Online (Sandbox Code Playgroud)
这里有一个 JSFiddle 演示来理解问题(记住扩展有另一个权限):http://jsfiddle.net/TH48e/40/
任何想法?
简单的Vimeo iframe点击不起作用:
$('iframe').click(function(){
alert('ok');
});
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
$('body').click(..
$(document).on('click','iframe',..
Run Code Online (Sandbox Code Playgroud)
但是当用户在悬停它时点击视频时,没有任何效果,它只播放视频.
javascript ×4
iframe ×3
jquery ×3
ajax ×1
click ×1
cors ×1
cross-domain ×1
dom ×1
firefox ×1
frame ×1
greasemonkey ×1
userscripts ×1
video ×1
vimeo ×1