2010-09-27
 
Kategorie
 

JavaScript Functions Available in A Layout

 

Sometimes, portions of your layout should only show or be hidden in specific situations. For example, a piece of text, some HTML code or a TradeDoubler script call should only appear on the Thank-You screen.

Until recently, we would write:

<script language="JavaScript">
    if (document.location.indexOf('/t') != -1) {
    (...)
    }
</script>

That was very cryptic and error-prone. Meanwhile, there is a set of JavaScript functions that allow you to apply the IF statement to your layout in a more sophisticated way:

  • getPlainURL() returns a ‘clean’ URL (with no parameters), e.g. without ‘renderer.slotId’
  • isEntryScreen() returns the information of whether we are on an EntryScreen (true or false)
  • isFormScreen() returns the information of whether we are on a form screen (true or false)
  • isConfirmationScreen() returns the information of whether we are on a ConfirmationScreen (true or false)
  • isThankyouScreen() returns the information of whether we are on a Thank-You screen (true or false)
  • getPageNumber() returns the current page number (for form screens; for other screens -1 is returned)

Correct IF statement usage for a Thank-You screen looks as follows:

<script language="JavaScript">
    if (isThankyouScreen()) {
    (...)
    }
</script>

These functions are easier and safer to use. Should the URLs of your forms change, your functions will still work (unlike in the case of document.location).

 
 
recent posts
3rd Apr 2014
Faster than ever!
5th Dec 2013
Live validation!
2nd Dec 2013
Features distilled
12th Mar 2012
Flicking Channels
26th Jan 2012
Your Own Error Page
9th May 2011
Box Properties
15th Apr 2011
Grouping Fields
13th Apr 2011
Form Versioning
24th Feb 2011
Form Access Modes
22nd Feb 2011
Required Fields
4th Feb 2011
Stats!