Page 1 of 1
Add javascript library equivalent to script tag in head?
Posted: Fri Jan 01, 2016 8:58 am
by Stefan Schnell
Hello community,
at first a happy new year to all.
Now my question:
I want to use the mobile detect library from here:
http://hgoebl.github.io/mobile-detect.js/ with the following code:
Code: Select all
; Begin-----------------------------------------------------------------
; Sub LoadScript------------------------------------------------------
Procedure LoadScript(script.s, *func)
!$.getScript(v_script, p_func);
EndProcedure
; Sub Main------------------------------------------------------------
Procedure Main()
!var md = new MobileDetect(window.navigator.userAgent);
EndProcedure
; Main----------------------------------------------------------------
LoadScript("mobile-detect.js", @Main())
; End-------------------------------------------------------------------
All I get is a reference error (Uncaught reference error: MobileDetect is not defined). What is my error?
Thanks for hints and tips.
Cheers
Stefan
Re: Add javascript library equivalent to script tag in head?
Posted: Sat Jan 02, 2016 6:08 am
by Stefan Schnell
Hello community,
I tried a little bit more and find out that the manually adding of
Code: Select all
<script type="text/javascript" src="mobile-detect.js"></script>
in the SpiderBasic_Compilation0.html works fine. On this case I can use the library without any errors. So I changed the program to add this code automatically, but I doesn't work also.
Code: Select all
; Begin-----------------------------------------------------------------
; Sub LoadScript------------------------------------------------------
Procedure LoadScript(script.s, *func)
!$.getScript(v_script, p_func);
EndProcedure
; Sub Main------------------------------------------------------------
Procedure Main()
!var v_script = document.createElement("script");
!v_script.setAttribute("type", "text/javascript");
!v_script.setAttribute("src", "mobile-detect.js");
!document.getElementsByTagName('head')[0].appendChild(v_script);
!var md = new MobileDetect(window.navigator.userAgent);
EndProcedure
; Main----------------------------------------------------------------
LoadScript("mobile-detect.js", @Main())
; End-------------------------------------------------------------------
Code: Select all
; Begin-----------------------------------------------------------------
; Sub LoadScript------------------------------------------------------
Procedure LoadScript(script.s, *func)
!$.getScript(v_script, p_func);
EndProcedure
; Sub Main------------------------------------------------------------
Procedure Main()
; Variables-------------------------------------------------------
Protected md.i
!v_md = new MobileDetect(window.navigator.userAgent);
EndProcedure
; Main----------------------------------------------------------------
!var v_script = document.createElement("script");
!v_script.setAttribute("type", "text/javascript");
!v_script.setAttribute("src", "mobile-detect.js");
!var v_head = document.getElementsByTagName("head")[0]
!v_head.insertBefore(v_script, v_head.firstChild);
;!v_head.appendChild(v_script);
LoadScript("mobile-detect.js", @Main())
; End-------------------------------------------------------------------
What is the correct way to add a JavaScript library in SpiderBasic equivalent to the script tag in the html header?
Thanks for tips and hints.
Cheers
Stefan
Re: Add javascript library equivalent to script tag in head?
Posted: Sat Jan 02, 2016 10:33 am
by Peter
Hello Stefan,
normally both methods ($.getScript() or adding the script to the header) should work.
It may be that it is a dojo/AMD-thing. Perhaps Fred knows more?
Greetings ... Peter
Re: Add javascript library equivalent to script tag in head?
Posted: Sat Jan 02, 2016 4:19 pm
by Stefan Schnell
Hallo Peter,
thank you very much for your reply.
Cheers
Stefan