Tuesday, 2 April 2013

Hubspot current.js code includes JQuery on it

Although I’m using Angular.js on the HubSpot TBot page (see Submitting TM users to HubSpot via TBOT interface (using Angular JS) ) I’m still more comfortable/knowledgeable in jQuery, so I decided to use it to populate the HubSpot fields.

So my first action was to load jQuery at the top of the TBot page:

image

which allowed me to do this:

image

(note the mix of JQuery and AngularJS code)

But then as I looked through the http://js.hubspot.com/forms/current.js file (which you will also notice that for TM, I saved it on the /_Customizations folder)

image

In the Util - Javascript Format (and Beautify).h2 O2 Platform tool:

image

I noticed that they had embedded jQuery in the current.js code, namely at the window.hsJQuery variable

image

this means that we can use jQuery to access the page’s DOM

image

Now, if we remove the jQuery script import:

image

the $ variable will not be available:

 image

But if we assign $ to window.hsJQuery, we are back in action:

image

Finally, we add that assignment to the TBot page

image

And the previous code (that used the $) is working again (now using the JQuery version from current.js)
Post a Comment