Results 1 to 5 of 5

Thread: Locally Override a Remote JavaScript Function

  1. #1
    Join Date
    Sep 2012

    Locally Override a Remote JavaScript Function

    Hello from the JavaScript newbie,

    I'm in process of creating some landing pages for my client's Google AdWords campaign. The landing page has info about the company, a call to action, etc. and lower down on the page is a form for the visitor to use if they would like to schedule an appointment.

    The appointment scheduler form comes from a company called DemandForce and as such, the process to embed the form on my page is as follows:

    <script type="text/javascript">
         d3cp_bid = '100000932'; // Business ID in DemandforceD3
         d3cp_appt_source = "Service Shop Scheduler";
         // Optional. The value will be displayed on D3 as the appointment request source.
         d3cp_appt_returnpage = "";
         // Optional. The URL will redirect after the appointment request is submitted. 
         // It can be an absolute URL path and a relative path to your page as well.
         // for example, d3cp_appt_returnpage = "https://www.acme.com/appointment/appointment.aspx".
    The problem I'm having is that the DemandForce JavaScript is setting focus to the 1st form field and because the form is a little bit "below the fold", the page is automatically scrolling to the form when the page loads, thus bypassing all of the info at the top part of the page.

    I think I've narrowed it down to the line of code on the DemandForce side. It's in a file called webscheduler.content.jsp:

    //set the first input of the form to be focused

    Because I'm not a JavaScript guru, I'm not really sure of the process of how the remote code is utilized by my page. Does (in effect) the DemandForce code get "sucked into" my page (as if were hard coded) and then executed? Is there a way to locally override the d3cp_focusFirstInputOfForm function that lives on the DemandForce servers so that I don't set focus to the form field? Someone at DemandForce suggested utilizing the following:

    <script> window.onload = function() {

    ...but it doesn't work - I'm guessing that in the chain of events the window.onload is happening prior to the DemandForce d3cp_focusFirstInputOfForm function.

    Thanks in advance for any help you can give me.

  2. #2
    Join Date
    Jul 2008
    urbana, il
    you might be able to reserve the name before the remote function loads.
    so before the external script tag,
    Object.defineProperty(window, "d3cp_focusFirstInputOfForm", {value:String});
    this may prevent it loading completely, or it may solve your problem without a hitch, good luck.

    if nothing else, a script tag at the bottom of your page to move the page back up might work:
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

  3. #3
    Join Date
    Sep 2012

    Typeerror returned

    Thanks for your reply - I tried to use the 1st option, but I am getting:
    A TypeError is thrown when attempts are made to change non-configurable property attributes (besides the writable attribute) unless the current and new values are the same.

    (The second option was one I already tried, but the window loads, scrolls down to the form and then jumps back up to the top and ends up looking not so good).

    Any suggestions on the error?

  4. #4
    Join Date
    Sep 2012
    oops - I pasted the wrong error info. Option 1 gives me:

    Timestamp: 9/20/2012 5:29:55 PM
    Error: TypeError: can't redefine non-configurable property 'd3cp_focusFirstInputOfForm'
    Source File: http://www.demandforced3.com/auto/addisonauto/scheduler.widget
    Line: 192
    Thanks for any help....

  5. #5
    Join Date
    Jul 2008
    urbana, il
    maybe you can add an onscroll event that will let you cancel the scroll by returning false or preventDefault() or something like that...
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.11823 seconds
  • Memory Usage 2,882KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (7)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (5)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates