Using GreyBox in your HTML Applications [con't]
|
My digging led me to the initFrame() function in the main gb_scripts.js file.
It is here that the iframe is created, using the AJS.IFRAME(d) function.
Not familiar with the AJS Framework, I had little idea how the function worked, but
I was able to ascertain that it used the document.createElement() method and set
various attributes according to the local d JSON Object variable:
The above code shows how GreyBox's succinct coding style can be difficult to follow.
To better help you follow the initFrame() function, here is the code again with formatting applied:
An easy way to include the APPLICATION attribute at the time that the iframe
is created is to add it directly to the d JSON Object:
Since the application attribute only applies to HTAs, it will simply be ignored by browsers.
If you want to call the previous fix a "sledgehammer", then the following would
be a more fine-grained solution. We can tell if we're running in an HTA by the
file extension. Don't bother checking for the <HTA:APPLICATION> tag because
its optional. The location.pathname property contains the file name part
of the URL. From there, The RegExp.test() function can easily determine whether
or not the file ends in an ".hta" extension. What we can do then is
call the AJS.createDOM() function directly with the iframe tag, which includes
the APPLICATION attribute. In Internet Explorer, the document.createElement()
function accepts whole tags in addition to just the tag name. Most people are
quite surprised to learn this, but the following code works like a charm:
The Loader Frame
The changes described above are enough to make the GreyBox script work within
your HTA, but you will also have to modify the loader_frame.html file if you
plan to reference the gb_scripts from the GreyBox content. The application="yes"
attribute must be added to the <IFRAME> tag for the "page" gb_type.
You can leave the image handling as-is because it is a static (I.E.: non-scripted)
page element:
Now you can include scripted elements to your page such as a link that closes the GreyBox frame:
I think that we've proved that sometimes it's OK to make minor changes to a framework's code. That's how you learn a lot of the time. Some of the best engineers were fascinated with how things worked and would dismantle and reassemble things until they fully understood it. Just remember to have someone knowledgeable in scripting review and OK your changes before putting them into a production environment.
Rob Gravelle combined his love of programming and music to become a software guru and accomplished guitar player. He created systems that are used by Canada Border Services, CSIS and other Intelligence-related organizations. As a software consultant, Rob has developed Web applications for many businesses and recently created a MooTools version of PHPFreechat for ViziMetrics. Musically, Rob recently embarked on a solo music career, after playing with Ivory Knight since 2000. That band was rated as one Canada's top bands by Brave Words magazine (issue #92) and released two CDs. In 2007, Rob recorded the KNIGHTFALL CD in collaboration with the former Ivory Knight vocalist and legendary guitarist/producer, Jeff Waters of Annihilator fame. A completely FREE high quality MP3 download of his "Ultraviolence" intrumental, is availalable from his website, www.robgravelle.com. Rob is available for short-term software projects and recording session work. to inquire, but note that, due to the volume of emails received, he cannot respond to every email. Potential jobs and praise receive highest priority!
Original: September 30, 2009
![]()




