0

I'm working on localhost (so would expect to not have any domain-related probs as here).

On a page I'm using a bit of JS to modify the content of a span in the opening-window. It does not work. When checking my code to find the control, it works (using FF dev-tools calling my Increment-function or checking the console.log-output): $('#uploads_Count')returns an object of type HTMLSpanElement. However, trying to access the same control from an opened window's console with window.opener.$('#uploads_Count'), this returns an HTML-Document, seemingly the entire page. Why is this not working, what am I missing here?

Here is function that is supposed to increment the counter contained in the span whose id is given as argument:

function Increment(ctrl)
{
   var gef = $("#" + ctrl);
   if (!gef) // did not find control, maybe on opener?
   {
      gef = window.opener.$("#" + ctrl);
   }
   console.log(gef);

   cnt = parseInt(gef.text() , 10);
   cnt++;
   gef.text(cnt);
}

The HTML is trivial:

<span id="uploads_Count">0</span>
4

2 回答 2

0

找到了!

我检查是否找到控件的方式是错误的。而不是if (!gef)我应该使用if (!gef.length). 在这里找到了解释。

于 2014-02-12T14:29:39.600 回答
0

如果$(selector)返回一个元素(例如HTMLSpanElement),而不是元素的集合(在大多数开发工具中看起来像[<span id="uploads_Count"></span>]),那么您就不会调用jQuery.

A 级浏览器中的开发工具倾向于$作为选择器功能引入。它仅在开发者控制台中可用。

如果window.jQuery存在,那么它很可能jQuery.noConflict()被调用,在这种情况下你应该使用window.opener.jQuery.

于 2014-02-10T16:01:02.547 回答