I have some JavaScript I have written for one of my _forms I placed it in shows.js.coffee and, at the bottom of the form included = javascript_include_tag 'shows'
When the page loads I get the $ not recognized error. If I move the include tag to my /layouts/application.html.haml and include it after I load my application.js then my JavaScript executes fine, but is not loaded onto every page. What do I need for it to just be loaded into the one page that needs it?
Related
I have a menu widget that I am trying to include on multiple pages. I have tried putting them in one php file and using php include. But the script part is being inserted right into the middle of the HTML and it comes before jQuery (at the bottom of the page) so it doesn't work.
How do I put the script part of the widget into the proper place (at the bottom of the page) while at the same time keeping the HTML and script together (in a file)?
I am working on a website that was started off by someone else. That person built the whole thing in one 1000-line html file, and links to different 'pages' just reference other sections in the main html file. So my task is to break the page apart into seperate html pages. Unfortunately, now the seperate pages do not load the javascript unless the page is refreshed.
Is there a standard way to fix this problem without forcing the user to manually refresh the page?
If you break that one big page into several smaller pages, make sure you include the JavaScript (and CSS) in the new pages. The most efficient way to do this is to have the JavaScript in an external JavaScript file, and bring that file into the new pages by putting the script tag inside the new pages' head tags like so:
<head>
<script src="path/to/javascript/app_name.js"></script>
</head>
When the user clicks on a hyperlink to see one of the new pages, when the browser receives the response from the server, it will parse the response and execute the JavaScript.
If I understand your problem correctly, I would wrap whatever "detailsScreen.js" does into a function and call it after you changed the page content.
I have a partial view that is loaded via an ajax call. Inside that partial, I have a textarea that is modified by a script. The script is used in other places across the site and is referenced in the _layout page...
<script src="~/Scripts/ckeditor/ckeditor.js"></script>
The script isn't working unless I place it in the partial view.
Its a ckeditor script for what its worth...
http://docs.ckeditor.com/#!/guide/dev_installation
This is not specific to this script though - it seems any script that needs to fire onload will fail on a run-time loaded partialview.
I would think that I should leave the script in a universal location like _layout rather than place it both in the _layout and add it to every partial its needed in.
Any ideas?
In my case, the script works by applying a class to a textarea...
#Html.TextAreaFor(model => model.business.act_comments, new { #class="ckeditor" })
I have coded a page that has two div one beside the other. The first one serves as a nav tree that, when clicked, loads a page in the right div with AJAX. I have to include a javascript file when one of the page is loaded.
I have managed to do jsut that and all works perfectly but each and every time that someone want to see the page, it includes the corresponding javascript page. This seems to me as a major leak and I am not so familiar with javascript development.
Question: Is there a way, when including the js file, to ensure that it was not previously included?
You could store the names of already loaded scripts in an array, and every time a load is requested, test if the script exist in the array or not.
You could alternatively attempt to check the src's of your script elements, if you load new scripts by appending new script elements into the document. Personally I've had some problems with that approach though.
Include the javascript in the main page HTML, not the page being loaded.
If you don't expect the page to be loaded overly much, you might get away with a guard inside your JS file to prevent redefinition:
if(typeof thisfilehasbeenincluded === "undefined")
{
var thisfilehasbeenincluded = true;
//rest of the file goes here
}
When i click on a Ajax.ActionLink, which displays a partial view, why does none of the javascritp associated with the partial view fire? This previously all worked before when I used Html.ActionLink. I have a series of scripts referenced in master page, which include $document.Ready functions. I have also tried added the script into the partial views themselves but they still don't fire. Any ideas?
javascript code dynamicly loaded into a div doesnt get recognised as executable code.
put the code in a function in a sepperate .js file, load this in your site.master and start executing by adding the
new AjaxOptions { oncomplete="myJavascriptFunction" }
to your Ajax.Actionlink