Invoking JavaScript code in an iframe from the parent page

Basically, I have an iframe embedded in a page and the iframe has some JavaScript routines I need to invoke from the parent page. Now the opposite is quite simple as you only need to call parent.functionName() , but unfortunately, I need exactly the opposite of that. Please note that my problem is not changing the source URL of the iframe , but invoking a function defined in the iframe . As

在父页面的iframe中调用JavaScript代码

基本上,我有一个iframe嵌入页面和iframe有一些JavaScript程序,我需要从父页调用。 现在相反很简单,因为你只需要调用parent.functionName() ,但不幸的是,我需要完全相反的。 请注意,我的问题不是更改iframe的源URL,而是调用iframe定义的函数。 假设你的iFrame的id是“targetFrame”,你想调用的函数是targetFunction() : document.getElementById('targetFrame').contentWindow.targetFunction(); 您也可以使用wind

Resizing an iframe based on content

I am working on an iGoogle-like application. Content from other applications (on other domains) is shown using iframes. How do I resize the iframes to fit the height of the iframes' content? I've tried to decipher the javascript Google uses but it's obfuscated, and searching the web has been fruitless so far. Update: Please note that content is loaded from other domains, so the

根据内容调整iframe的大小

我正在研究一个类似iGoogle的应用程序。 来自其他应用程序(在其他域中)的内容使用iframe显示。 如何调整iframe的大小以适应iframes内容的高度? 我试图破译Google使用的JavaScript,但它被混淆了,并且搜索网页到目前为止一直没有成果。 更新:请注意,内容是从其他域加载的,因此适用同源策略。 我们遇到了这种类型的问题,但与您的情况稍有相反 - 我们正在向其他域中的站点提供iframed内容,因此同一起源策略也是一

Traverse a table using jQuery, XML, JSON, JS

Sorry for the misleading title but I'm unsure how else to write it. I have the below table... I want to produce a simple calculator that compares all data in a row from 2 given parameters. I will ask my users to select a country first, and then select a value in that column. After doing this you can submit the form and it would output the correct values from that given row... I'v

使用jQuery,XML,JSON,JS遍历一个表

对不起,误导性的标题,但我不确定如何写它。 我有下面的表格...... 我想制作一个简单的计算器,比较2个给定参数中的所有数据。 我会要求我的用户先选择一个国家,然后在该列中选择一个值。 做完这些之后,您可以提交表单,并从该行输出正确的值。 我做了一个小提琴试图展现我的意思...... http://jsfiddle.net/SLCaN/2/ 做这个的最好方式是什么? 我知道的唯一方法是拥有一个巨大的if / else语句,这将使我永远写

JSLint: Using a function before it's defined error

I'm using JSLint to verify most of my external Javascript files, but the largest amount of errors I'm getting is from functions being used before they're defined. Is this really an issue I should worry about ? It seems Firefox, IE7 and Chrome don't care. Functions like the popular init() (which I use often) normally stick at the top as that makes sense to me (I like to preten

JSLint:在定义错误之前使用函数

我使用JSLint来验证我的大部分外部Javascript文件,但是我得到的最大错误是来自函数在定义之前使用的。 这真的是我应该担心的问题吗? 看来Firefox,IE7和Chrome都不在乎。 根据JSLint的说法,像常用的init() (我经常使用)的函数通常会粘在顶部,因为这对我来说很有意义(我喜欢假装它类似于main() ),它需要推到底部文件。 如果使用function关键字声明函数,则可以在声明它们之前使用它们。 但是,如果通过其他方法

Flat JSON to hierarchy/tree without ID

Helloo, I'm trying to convert a flat JSON to a tree structure and I'm curious if this is possible or not. Any help completing my problem would be greatly appreciated. Below is what I have currently tried and am working on. This only successfully get the first set of children and they're children. I haven't been able to make it passed this point. I fear this may not be possib

将JSON平坦化为没有ID的层次结构/树

Helloo,我试图将一个扁平的JSON转换为树形结构,我很好奇这是否可行。 任何帮助完成我的问题将不胜感激。 以下是我目前正在尝试和正在研究的内容。 这只能成功获得第一批孩子,而且他们是孩子。 我无法通过这一点。 我担心这可能是不可能的。 我在开始之前就知道根,所以我认为它应该是可能的。 对于这种情况,根源是“提供自动军事卫生系统功能”。 JSON树最终会看起来像: { "name": "Provide Autom

Unique counts in JavaScript array, sorted by counts

I have a list of names in JavaScript. What I'd like to do is get the list of unique names, but for that list of unique names also provide a count of how many there are in my original list. Furthermore, I need to sort my final list of unique names by count in descending order (then ascending order by name in case some have the same counts). Here's what I have which is just a simple lis

JavaScript数组中的唯一计数,按计数排序

我有一个JavaScript的名字列表。 我想要做的是获取唯一名称列表,但是对于该唯一名称列表,还会提供我原始列表中有多少个名称的计数。 此外,我需要按降序排列我的唯一名称的最终列表(如果某些计数相同,则按名称升序排列)。 这就是我所拥有的只是一个简单的字符串列表,然后给了我唯一名称列表。 从这里,我不确定在哪里获得计数或如何通过计数来对唯一列表进行排序。 我在想最终的结果将是一个二维数组的名称和数量或2

"dot function" operator in JavaScript

I'm a total newbie in js, so please be gentle with me :) I want to understand where can we use the dot operator on some variable (in this case - an array), and when we cannot. consider the following code: //example 1 function f1(x) { return x*x; } console.log(map(f1, [1,2,3,4,5])); console.log([1,2,3,4,5].map(f1)); //example 2 function f2(arr) { return arr; } console.log(f2([1,2,

JavaScript中的“点函数”操作符

我是js的新手,所以请对我温柔:) 我想知道我们在哪里可以使用某个变量的点运算符(在这种情况下是一个数组),什么时候我们不能。 考虑下面的代码: //example 1 function f1(x) { return x*x; } console.log(map(f1, [1,2,3,4,5])); console.log([1,2,3,4,5].map(f1)); //example 2 function f2(arr) { return arr; } console.log(f2([1,2,3,4,5])); console.log([1,2,3,4,5].f2()); 我知道这些例子是相当不同的

Why modifying `Array.prototype` doesn't work?

Please refer - https://jsfiddle.net/53ranmn5/1 Array.prototype.method1 = function() { console.log("method1 called"); } [1,2,3,4].method1(); I get the following error, TypeError: Cannot read property 'method1' of undefined Why so? How can I fix this? You're missing a semicolon: Array.prototype.method1 = function() { console.log("method1 called"); }; // <--- Hi there! [

为什么修改`Array.prototype`不起作用?

请参阅 - https://jsfiddle.net/53ranmn5/1 Array.prototype.method1 = function() { console.log("method1 called"); } [1,2,3,4].method1(); 我收到以下错误, TypeError:无法读取undefined属性'method1' 为什么这样? 我怎样才能解决这个问题? 你错过了一个分号: Array.prototype.method1 = function() { console.log("method1 called"); }; // <--- Hi there! [1,2,3,4].method1(); 什么?

Sort an array based on the length of each element

I have an array like this: arr = [] arr[0] = "ab" arr[1] = "abcdefgh" arr[2] = "abcd" After sorting, the output array should be: arr[0] = "abcdefgh" arr[1] = "abcd" arr[2] = "ab" I mean, I want in the descending order of the length of each element. You can use Array.sort method to sort the array. A sorting function that considers the length of string as the sorting criteria can be used a

根据每个元素的长度对数组进行排序

我有一个这样的数组: arr = [] arr[0] = "ab" arr[1] = "abcdefgh" arr[2] = "abcd" 排序后,输出数组应该是: arr[0] = "abcdefgh" arr[1] = "abcd" arr[2] = "ab" 我的意思是,我想按照每个元素长度的降序排列。 您可以使用Array.sort方法对数组进行排序。 将字符串长度作为排序标准的排序函数可以按如下方式使用: arr.sort(function(a, b){ // ASC -> a.length - b.length // DESC -> b.length - a.len

The best way to remove array element by value

I have an array like this arr = ["orange","red","black","white"] I want to augment the array object defining a deleteElem() method which acts like this: arr2 = arr.deleteElem("red"); // ["orange","black","white"] (with no hole) What is the best way to accomplish this task using just the value parameter (no index)? Here's how it's done: var arr = ["orange","red","black","white"]; va

按值删除数组元素的最佳方法

我有一个这样的数组 arr = ["orange","red","black","white"] 我想增加定义一个deleteElem()方法的数组对象,它的行为如下所示: arr2 = arr.deleteElem("red"); // ["orange","black","white"] (with no hole) 使用value参数(无索引)完成此任务的最佳方法是什么? 这是如何完成的: var arr = ["orange","red","black","white"]; var index = arr.indexOf("red"); if (index >= 0) { arr.splice( index, 1 ); }