Dynamically load a JavaScript file

You may create a script element dynamically, using Prototypes: new Element(“script”, {src: “myBigCodeLibrary.js”, type: “text/javascript”}); The problem here is that we do not know when the external script file is fully loaded. We often want our dependant code on the very next line and like to write something like: if (iNeedSomeMore) { Script.load(“myBigCodeLibrary.js”); // includes … Read more

Can we call the function written in one JavaScript in another JS file?

The function could be called as if it was in the same JS File as long as the file containing the definition of the function has been loaded before the first use of the function. I.e. File1.js function alertNumber(number) { alert(number); } File2.js function alertOne() { alertNumber(“one”); } HTML <head> …. <script src=”https://stackoverflow.com/questions/3809862/File1.js” type=”text/javascript”></script> <script … Read more

How to include another XHTML in XHTML using JSF 2.0 Facelets?

<ui:include> Most basic way is <ui:include>. The included content must be placed inside <ui:composition>. Kickoff example of the master page /page.xhtml: <!DOCTYPE html> <html lang=”en” xmlns=”http://www.w3.org/1999/xhtml” xmlns:f=”http://xmlns.jcp.org/jsf/core” xmlns:h=”http://xmlns.jcp.org/jsf/html” xmlns:ui=”http://xmlns.jcp.org/jsf/facelets”> <h:head> <title>Include demo</title> </h:head> <h:body> <h1>Master page</h1> <p>Master page blah blah lorem ipsum</p> <ui:include src=”/WEB-INF/include.xhtml” /> </h:body> </html> The include page /WEB-INF/include.xhtml (yes, this is the … Read more

ASP.NET MVC 3 Razor: Include JavaScript file in the head tag

You can use Named Sections. _Layout.cshtml <head> <script type=”text/javascript” src=”https://stackoverflow.com/questions/4311783/@Url.Content(“/Scripts/jquery-1.6.2.min.js”)”></script> @RenderSection(“JavaScript”, required: false) </head> _SomeView.cshtml @section JavaScript { <script type=”text/javascript” src=”https://stackoverflow.com/questions/4311783/@Url.Content(“/Scripts/SomeScript.js”)”></script> <script type=”text/javascript” src=”https://stackoverflow.com/questions/4311783/@Url.Content(“/Scripts/AnotherScript.js”)”></script> }

Get absolute path of initially run script

__FILE__ constant will give you absolute path to current file. Update: The question was changed to ask how to retrieve the initially executed script instead of the currently running script. The only (??) reliable way to do that is to use the debug_backtrace function. $stack = debug_backtrace(); $firstFrame = $stack[count($stack) – 1]; $initialFile = $firstFrame[‘file’];

Detecting superfluous #includes in C/C++?

Google’s cppclean (links to: download, documentation) can find several categories of C++ problems, and it can now find superfluous #includes. There’s also a Clang-based tool, include-what-you-use, that can do this. include-what-you-use can even suggest forward declarations (so you don’t have to #include so much) and optionally clean up your #includes for you. Current versions of … Read more

What is the purpose of Android’s tag in XML layouts?

<merge/> is useful because it can get rid of unneeded ViewGroups, i.e. layouts that are simply used to wrap other views and serve no purpose themselves. For example, if you were to <include/> a layout from another file without using merge, the two files might look something like this: layout1.xml: <FrameLayout> <include layout=”@layout/layout2″/> </FrameLayout> layout2.xml: … Read more