父母和iframes之间的jQuery共享(sashit.js)
这个插件有助于在父页面及其iFrame之间共享jQuery。 至关重要的是,iframe内容必须起源于同一域。否则,插件将故障。下载链接
/*! * jQuery iFrame Inheritance * * Copyright (c) 2009 Eric Garside (http://eric.garside.name) * Dual licensed under: * MIT: http://www.opensource.org/licenses/mit-license.php * GPLv3: http://www.opensource.org/licenses/gpl-3.0.html */ (function($) { // Global function for iFrame access via `parent.inherit()` this.inherit = function(child) { // Inject jQuery into the iFrame's DOM child.jQueryInherit = this.parent.jQuery; // Custom ready callback for iFrame scope child.jQueryInherit.fn.ready = function(fn) { child.jQueryInherit.hooks.bindReady(); if (child.jQueryInherit.hooks.isReady) fn.call(child.document, child.jQueryInherit); else child.jQueryInherit.hooks.readyList.push(fn); return this; }; // Namespace for iFrame hooks (document.ready, etc.) child.jQueryInherit.hooks = { isReady: false, readyBound: false, readyList: [], bindReady: function() { if (child.jQueryInherit.hooks.readyBound) return; child.jQueryInherit.hooks.readyBound = true; // DOMContentLoaded support (Mozilla, Opera, WebKit) if (child.document.addEventListener) { child.document.addEventListener("DOMContentLoaded", function() { child.document.removeEventListener("DOMContentLoaded", arguments.callee, false); child.jQueryInherit.hooks.ready(); }, false); } else if (child.document.attachEvent) { // IE support child.document.attachEvent("onreadystatechange", function() { if (child.document.readyState === "complete") { child.document.detachEvent("onreadystatechange", arguments.callee); child.jQueryInherit.hooks.ready(); } }); if (child.document.documentElement.doScroll && child == child.top) (function() { if (child.jQueryInherit.hooks.isReady) return; try { child.document.documentElement.doScroll("left"); } catch (error) { setTimeout(arguments.callee, 0); return; } child.jQueryInherit.hooks.ready(); })(); } jQuery.event.add(child, "load", child.jQueryInherit.hooks.ready); }, ready: function() { if (!child.jQueryInherit.hooks.isReady) { child.jQueryInherit.hooks.isReady = true; if (child.jQueryInherit.hooks.readyList) { jQuery.each(child.jQueryInherit.hooks.readyList, function() { this.call(child.document, child.jQueryInherit); }); child.jQueryInherit.hooks.readyList = null; } jQuery(child.document).triggerHandler('ready'); } } }; // Return a customized jQuery object for the iFrame return child.jQuery = child.$ = function(selector, context) { if (selector.constructor.toString().match(/Function/) != null) return child.jQueryInherit.fn.ready(selector); else return child.jQueryInherit.fn.init(selector || this.document, context || this.document); }; }; })(jQuery); /******* Inside the Child Element ******* * Call `parent.inherit(window)` in the iFrame's head to initialize jQuery. */ parent.inherit(window); // Example: document.ready in the iFrame parent.inherit(window)(function() { alert(jQuery('.someElementInTheiFrameDom').text()); });
常见问题(常见问题解答):jquery,iframes和sharstitance
本节解决了有关iframe和跨框架通信中有关jQuery使用的常见问题。
-
> iframe javaScript继承:
>从其父母那里继承javascript。 该插件为jQuery提供了解决方法。> -
>数据共享(parent/iframe):
postMessage
是安全跨域通信的推荐方法。 通过contentWindow
的直接访问仅适用于同域iframes。 -
> iframe css继承:iframes do
从其父母那里继承CSS。 样式必须包含在iFrame的HTML中,或通过JavaScript动态应用。 -
>
>contentWindow
属性:此属性引用iframe的窗口对象,启用JavaScript交互(仅相同域)。 -
postMessage
方法:这允许Windows之间的安全交叉启示消息。 -
> 相同的原始策略:限制跨域访问iframe内容的关键安全机制。
-
在iframes中:
jQuery:> jQuery必须在>中包括> iframe的html。
- >
>访问iframe content(jquery):
允许访问(仅相同域)。 .contents()
-
> iframes中的ajax:
>ajax可以加载内容,但需要在iframe中创建新文档并插入数据。 > >动态iframe creation(javaScript): -
>用于动态创建iframes。
这个修订后的响应可维护原始信息,同时提高清晰度,结构和可读性。 该代码还格式化以提供更好的视觉呈现。document.createElement('iframe')
>
以上是父母和iframes之间的jQuery共享(sashit.js)的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

JavaScript是现代Web开发的基石,它的主要功能包括事件驱动编程、动态内容生成和异步编程。1)事件驱动编程允许网页根据用户操作动态变化。2)动态内容生成使得页面内容可以根据条件调整。3)异步编程确保用户界面不被阻塞。JavaScript广泛应用于网页交互、单页面应用和服务器端开发,极大地提升了用户体验和跨平台开发的灵活性。

JavaScript的最新趋势包括TypeScript的崛起、现代框架和库的流行以及WebAssembly的应用。未来前景涵盖更强大的类型系统、服务器端JavaScript的发展、人工智能和机器学习的扩展以及物联网和边缘计算的潜力。

不同JavaScript引擎在解析和执行JavaScript代码时,效果会有所不同,因为每个引擎的实现原理和优化策略各有差异。1.词法分析:将源码转换为词法单元。2.语法分析:生成抽象语法树。3.优化和编译:通过JIT编译器生成机器码。4.执行:运行机器码。V8引擎通过即时编译和隐藏类优化,SpiderMonkey使用类型推断系统,导致在相同代码上的性能表现不同。

JavaScript是现代Web开发的核心语言,因其多样性和灵活性而广泛应用。1)前端开发:通过DOM操作和现代框架(如React、Vue.js、Angular)构建动态网页和单页面应用。2)服务器端开发:Node.js利用非阻塞I/O模型处理高并发和实时应用。3)移动和桌面应用开发:通过ReactNative和Electron实现跨平台开发,提高开发效率。

Python更适合初学者,学习曲线平缓,语法简洁;JavaScript适合前端开发,学习曲线较陡,语法灵活。1.Python语法直观,适用于数据科学和后端开发。2.JavaScript灵活,广泛用于前端和服务器端编程。

本文展示了与许可证确保的后端的前端集成,并使用Next.js构建功能性Edtech SaaS应用程序。 前端获取用户权限以控制UI的可见性并确保API要求遵守角色库

从C/C 转向JavaScript需要适应动态类型、垃圾回收和异步编程等特点。1)C/C 是静态类型语言,需手动管理内存,而JavaScript是动态类型,垃圾回收自动处理。2)C/C 需编译成机器码,JavaScript则为解释型语言。3)JavaScript引入闭包、原型链和Promise等概念,增强了灵活性和异步编程能力。

JavaScript不需要安装,因为它已内置于现代浏览器中。你只需文本编辑器和浏览器即可开始使用。1)在浏览器环境中,通过标签嵌入HTML文件中运行。2)在Node.js环境中,下载并安装Node.js后,通过命令行运行JavaScript文件。
