How to include my javascript file after Telerik includes their javascript - javascript

I would like to override Tekerik's javascript function. To do that I want to include a file that contains modified javascript after Telerik's js include.
I include my js files using ClientScriptManager.RegisterClientScriptBlock method. My files are included before Telerik's preventing me from overriding their function.
<script type="text/javascript" src="myScriptFile.js"></script>
<script src="/atlas/Telerik.Web.UI.WebResource.axd?....></script>
How can I include my javascript file after Telerik's?

One option that I found is to use RegisterStartupScript method that
"emits the script just before the closing tag of the Page object's <form runat= server> element."
which is after Telerik includes their files. This doesn't include a js file but at this point I can call a function that overrides Telerik's function.

Assuming you want to do this globally, had you considered editing the Telerik source file rather than overriding it?

Related

How sets location of HTML,Javascript and CSS files for create a table?

http://jsfiddle.net/davidThomas/dYnqv/
I use that code. I create a folder which names tableEx. Then I put (table.html) and others(folder). In others folder I put (table.js) and (table.css).
Then I opened html file with notepad++ and referenced like that =>
<script src = "others//table.js"> </script>
<link rel="stylesheet" href="others//table.css"/>
table.css is work but table.js is not. why?
You need to combine answers of these two guys. jeff's telling you to replace // for just / and what the other guy is saying is, that the jsfiddle link you took the code from has built-in javascript library called jQuery, in what your javascript code is written in (see the dollar symbol ? it's one of the jquery-specific identifier)
So for your code to work on your computer, you also need to call for this library jQuery, you don't have to download it (but can), simply use some online ones (CDN) by inserting this external js call in html tags, preferably before your js file so it already knows what language it is written in:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>

Include javascript file in jsp from anothe javascript file dynamically

Is it possible to include a javascript files in jsp dynamiacalyy, ie. in any listener or anything like that from the current javascript file. This is for speeding up the page load.
Yes, there are multiple options, for example jQuery has $.getScript method. Or you can use http://requirejs.org/

How do you import multiple javascript files in HTML index file without the bloat?

Is there anyway of importing multiple javascript files in HTML without having to specify each file?
<script src="js/toolkit/Toolkit.js"></script>
<script src="js/toolkit/Viewable.js"></script>
<script src="js/toolkit/Overlay.js"></script>
ie. can I specify something like js/toolkit/* ?
I have 50+ javascript files that i have to import, and to specify each file seems very time consuming.
Including a JavaScript file in another JavaScript file is common in web development.
Because many times we include the JavaScript file at run time on the behalf of some conditions.
So, we can achieve this using JavaScript as well as using jQuery.
Method 1: Use JavaScript to include another JavaScript file
Add the following function in your web page.
function loadScript(url)
{
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
head.appendChild(script);
}
just call the below loadScript function, where you want to include the js file.
loadScript('/js/jquery-1.7.min.js');
Method 2: Use jQuery to include another JavaScript file.
Add jQuery File in your webpage.
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
Just call the getScript function functions.
jQuery(document).ready(function(){
$.getScript('/js/jquery-1.7.min.js');
});
How to include a JavaScript file in another JavaScript File
There's a way:
You can create a javascript function that takes the path as a parameter and creates these HTML lines:
<script src="js/toolkit/Toolkit.js"></script>
<script src="js/toolkit/Viewable.js"></script>
<script src="js/toolkit/Overlay.js"></script>
And you'll just have to call this:
loadLib("toolkit/Toolkit");
loadLib("toolkit/Viewable");
loadLib("toolkit/Overlay");
But this is not recommended because the load time will be increased due to the number of HTTP requests.
You should better use something in the server side to put everything in the same file.
No you can't do it. And by the way this is not good idea to load all 50 separate files. Consider compressing them in one single script to improve performance and decrease page load time.
You can setup grunt to watch the folder of the scripts and concat/minify them into a single file, then you just have to include that in your HTML file.
You will need to specify each file for the browser to know what to retrieve, but depending on the IDE you are using, there may be shortcuts for doing this, (Visual Studios allows you to drag and drop script files into the html to add references).
During development, you want to do just as your doing by keeping the files separate for troubleshooting, but in production, as others have commented, its very good practice to minify your code and combine them into one file. That makes it only one call, and can reduce your overhead significantly.
I recommend you to use JSCompress. It will compress all your javascript code into one single javascript file.
import "./angular.min.js"
import "./jquery-3.6.0.min.js"
import "./app.js"
<script type="module" src="js/importJS.js"></script>

Extract javascript from JSP to JS file

I'm trying to refactor parts of our front-end at the moment, using Intellij. We have a lot of javascript that is within our JSPs. I'd like to be able to extract from the JSP into a .js fil and replace it with a script tag referencing that file. I know how to extract to an 'includes' file, but I'd like a way of extracting and replacing the code with a proper script tag.
Does anyone know of a plugin that can accomplish this quickly and easily? (Or a pre-existing function in Intellij that I'm unaware of)
Please vote for this issue (it's 5 years old and had zero votes).
just create one file with .js extension copy and paste your js codes with their function names. then include that file in your jsp project header section.
eg:
<script type="text/javascript" src="js/jquery-ui.min.js"></script>
thats all..

How to get visual studio to recognize a cshtml file as javascript

I am writing a css/js page that has some dynamic parts in it.
To do this i am using a cshtml file containing css/js - i am using mvc.net and returning the css from a controller action.
The trouble is visual studio recognizes this page as html and not as javascript/css so it does not give me javascript/css coloring and IntelliSense.
My questions:
is there a better/easier way of creating dynamic css/js in .net
How can i get visual studio to recognize a cshtml page as javascript.
I know this is an old post...but...
What I did was just put the script tags around my javascript files in their own .cshtml file.
I created a separate controller (JavascriptController.cs), and I created a filter on that controller that removes the script tags. I set the filter in the OnActionExecuting method. by just doing
this.Response.Filter = new ScriptFilter(Response.Filter, Response.ContentEncoding);
So you get the syntax, you get razor without having to use RazorJS, and you can request the js files like regular routes in an MVC application. You just have to keep the script tags on the partial view while editing.
So you can call
/Javascript/{Action}
and you'll get your javascript file with your razor in it, and the filter will remove the script tags so you can include it like a normal script.
<script src="http://{host}/Javascript/{action}"></script>
What is wrong with putting <script> and <style> tags in a page and put your dynamic js/css there , in the end if it is dynamic there is no way for caching it so this approach will be fine.
you can write something like below:
<script>
function myFunction_#MyFunc(params)(obj) { return obj.field + #MyOtherFunc(params); }
<script>
and razor engine will evaluate #MyFunc(params) and #MyOtherFunc(params) before sending it to browser
The best solution is to follow unobtrusive javascript and unobtrusive styling and put your javascript into a .js file, put your css into a .css file and reference them in the markup in your cshtml file with a <script> and <link> tag.
e.g.
<script src="Scripts/scriptName.js" type="text/javascript"></script>
<link rel="stylesheet" href="Content/styleSheetname.css" type="text/css" />
This is good practice as it keeps your content(markup)/styling/behaviour separate.
For JavaScript you could try the RazorJS nuget package. But we've run into some inconsistencies while using it.
Still trying to find a better way to do this using Controller/Views and still be able to use intellisense and get decent coloring.

Categories