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

What is the difference between XSP.getElementById and document.getElementById? In my tests both seem to

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745155580a4614100.html

相关推荐

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

    What is the difference between XSP.getElementById and document.getElementById? In my tests both seem to

    5小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信