最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - XSP.getElementById vs document.getElementById - Stack Overflow

programmeradmin1浏览0评论

What is the difference between XSP.getElementById and document.getElementById? In my tests both seem to return the same value (value stored in field). Which one should be preferred while coding for XPages?

What is the difference between XSP.getElementById and document.getElementById? In my tests both seem to return the same value (value stored in field). Which one should be preferred while coding for XPages?

Share Improve this question asked Feb 1, 2013 at 16:59 NaveenNaveen 6,93610 gold badges41 silver badges85 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

edited

XSP.getElementById is the same as dojo.byId which I believe works in wider range of browsers than document.getElementById.

Here is the source for XSP.getElementById:

   /**
    * Convenience function for retrieving an element given its id in a browser independent manner.
    */
    this.getElementById = function x_gbi(elementId){
        return dojo.byId(elementId);
    }

I guess for better future XPage support it might be a good idea to use XSP.getElementById (because they might change it) instead of dojo.byId. I've been using dojo.byId because it's shorter. document.getElementById should never be used in XPages because we have dojo.byId.

update

Starting from Dojo 1.7 the syntax is much more plex:

require(["dojo/dom"], function(dom){
    // fetch a node by id="someNode"
    var node = dom.byId("someNode");
});

Today my colleque pointed out that Dojo 2 will not support the current simple way of calling dojo.byId any more. This means that XSP.getElementById is definitely the way to go and we should start using the new require based syntax whenever we use Dojo with ND9.

XSP contains code for handling situations with the Notes client (XPiNC) and the web browser. Not using XSP calls in XPiNC may work or may have side effects.

XSP.getElementById works the same way as document.getElementById except it ensures that it works across browsers with the same functionality.

You can read more about how XSP works in the "XPages Portable Command Guide" Page 184 for getElementById.

发布评论

评论列表(0)

  1. 暂无评论