Advertisement
Guest User

Untitled

a guest
Jun 15th, 2012
1,964
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. The Image Onload Technique Used With QuickBase
  2. ==============================================
  3.  
  4. The image onload technique is a workaround that allows you to load and
  5. execute a user supplied javascript file immediately upon loading one of
  6. the following five types of pages:
  7.  
  8. 1) create new record;
  9. 2) view existing record;
  10. 3) edit existing record;
  11. 4) report listing; and
  12. 5) grid edit
  13.  
  14. It is a safe and flexible technique and is one of only two ways of
  15. accomplishing this feat. I am not telling anyone the second way in
  16. case the first technique goes away.
  17.  
  18. It works because an image with an onload attribute will execute the specified
  19. code when the page is loaded. Because jQuery is now served as part of every
  20. page the method $.getScript(url) can specify what user defined page should be
  21. loaded and the customized javascript can perform various patchwork to the page
  22. as if that javascript was originally part of the served page. The are a number
  23. of additional tricks employed that are quite technical but luckily you will
  24. probably never have to changed them.
  25.  
  26. The following three step procedure describes the essential steps.
  27.  
  28. STEP 1
  29.  
  30. Create a field with the following formula definition and include it in your
  31. form/report. You will never have to modify this formula other than to possibly
  32. change the name of the user defined page (module.js). Although we are inserting
  33. this field into the form/report we take every possible step to hide its
  34. appearance on the form
  35.  
  36. I often use a hyphen or minus sign for the name of the field.
  37.  
  38. [- (text formula field with some HTML allowed)]=
  39. "<img qbu=\"module\" src=\"/i/clear2x2.gif\" " &
  40. "onload=\"javascript:if(typeof QBU=='undefined'){QBU={};$.getScript('" &
  41. URLRoot() &
  42. "db/" &
  43. Dbid() &
  44. "?a=dbpage&pagename=module.js&rand='+Math.random())}\">"
  45.  
  46. ==================================================
  47. STEP 2
  48.  
  49. Create a user defined Page named "module.js" and place your custom code
  50. in the section under the alert statement. You do not need to prefix your
  51. javascript variables with QBU_ to avoid namespace collisions if they are
  52. place with in the "self executing anonymous function" (function(){ ...})();
  53. that acts as a wrapper.
  54.  
  55. (function(){
  56.  
  57. var querystring=document.location.search;
  58.  
  59. if (/dlta=mog/.test(querystring)) {
  60. //GRID EDIT PAGE ========================================
  61. alert("You are on the Grid Edit Page");
  62.  
  63. } else if(/a=er/.test(querystring)) {
  64. //EDIT RECORD PAGE ========================================
  65. alert("You are on the Edit Record Page");
  66.  
  67. } else if (/GenNewRecord/.test(querystring)) {
  68. //ADD RECORD PAGE ========================================
  69. alert("You are on the Add Record Page");
  70.  
  71. } else if(/a=dr/.test(querystring)) {
  72. //DISPLAY RECORD PAGE
  73. $("img[qbu=module]").closest("td").css("background-color","#FFFFFF");
  74. alert("You are on the Display Record Page");
  75.  
  76. } else if(/a=q/.test(querystring)) {
  77. //REPORT PAGE ========================================
  78. alert("You are on the Report Listing Page");
  79.  
  80. } else {
  81. //OTHER PAGE ========================================
  82. alert("You are on the Some Other Page");
  83. }
  84.  
  85. })();
  86.  
  87. ==================================================
  88.  
  89. STEP 3
  90.  
  91. In any form where you include the field [-] select alternate label text and
  92. leave the text empty. This in conjunction with the code in the user defined
  93. page will hide the presence of the field on the form.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement