I found out IE has different behavior vs Firefox when I use this
$('head').prepend('');
That basically just to add the theme-2.css on top within HEAD tag (for theme purpose). I do that because I don't want it to load yet because I use the csspreload http://www.filamentgroup.com/lab/update_automatically_preload_images_from_css_with_jquery/
In Firefox, the .css file on top will be taken over in priority by files below. This works fine!
In IE, the NEW .css file being added later into HEAD will take effect. This doesn't matter it is on top or bottom.
How to fix this behavior for IE?
Is there a different image loader that I can input .css files into parameters and it loads from there? The current one must see .css file in link within html.
Thanks
I'm not entirely clear on what you're trying to accomplish here - are you attempting to add a stylesheet to the page dynamically without having it affect the page, in order to preload its images?
If so, this snippet might do want you want:
$('link[rel="stylesheet"][href="theme-2.css"]').attr('disabled', 'disabled');
That will disable the stylesheet, but it will remain loaded. If you want to turn it back on in the future you can do this:
$('link[rel="stylesheet"][href="theme-2.css"]').removeAttr('disabled');
Edit:
What you really want, I suppose, is the functionality from the disabled attribute. You can actually set this when you prepend that stylesheet, and it won't be applied to the page. The snippets above just demonstrate how to do this dynamically.
First of all, there probably isn't a method of successfully doing what you want in Internet Explorer. Unless, in IE, you add the existing stylesheets again after you load the stylesheet in question.
Second, why not just modify the existing plugin?
Call it with:
$.preloadCssImages({extra: [{href: "/css/styles.css"}]});
Or if you have multiple extra CSS files:
$.preloadCssImages({extra: [{href: "/css/styles.css"}, {href: "/css/styles2.css"}]});
Etc.
Then, after the "parseCSS(document.styleSheets)" line at the bottom of the file, insert:
if (settings.extra)
{
parseCSS(settings.extra);
}
Easy peasy.
Related
CKEditor 4 or above
I have a CKEDITOR instance that I can access without problem parent.CKEDITOR.instances[instance_id]
I want to add bootstrap file to the head of the iframe generated by CKEDITOR (kind of hack, because normal way to add optional css file was not working).
I tried to get the iframe head and to inject the bootstrap file, but it fails always.
Any Suggestion?
If you are using classic editor with contents in iframe then please use contentsCss configuration setting to add extra CSS to editor contents area. It is important to refresh the cache with Ctrl+F5. If for some reason changes are not applied and path to CSS file is correct (you are not getting 404 in browser dev-tools console) then you might want to try clearing cache according to this link.
If you really need to get to the iframe, you can use below technique. It gets you the div with editor id you need and it finds iframe for it. This is good if you have couple of editors or iframes on a single page.
document.getElementById('cke_'+ your_textarea_id ).getElementsByTagName('iframe')[0].contentWindow
I found it finally, I post it here so maybe it will be helpful for someone in the future.
I just added the bootstrap file to the body tag (it is a bad practice but it works).
I am writing a free online e-book which needs a few minor formatting tweaks:
http://rperl.org/learning_rperl.html
The "Full Table Of Contents" at the very top of the page starts out by being visible for a few seconds, then finally collapses itself to be hidden. What we need is for it to start as hidden, and not be visible at all for the several seconds while the page loads. You can see that I have already tried to solve this issue by setting "var index_hidden=1;" at the following link, otherwise the table of contents would never hide itself at all:
https://github.com/wbraswell/rperl/blob/gh-pages/javascripts/metacpan_rperl.js#L832-L833
It probably shouldn't matter, but I'm using some custom Perl scripts to generate this file from Perl POD source, I can give more info if needed.
Although the described behavior does not appear for me (OSX + Firefox). Here's what you might do:
Hide the element by default using CSS. Add this to your head element (extend with stronger hiding CSS when needed).
<style>.wait-for-js { display: none; }</style>
And hide your element by adding the class
<div id="index-container" class="hide-index wait-for-js">
Last but not least, to make this trick functional. Remove the class as soon as JS is loaded, which would also mean that other logic has been loaded and you're save to show the table of contents. Be sure to load this JavaScript last thing you'll do.
<script>
document.getElementById('index-container').className = 'hide-index';
</script>
Or if you're using jQuery
<script>$('.wait-for-js').removeClass('wait-for-js');</script>
Welcome to SO!
When I click a botton I make an ajax call which loads different html code inside a div with the id 'main'. I have no problems getting the html code to show, but I can't find a way to change/add/include css and js code to my current page.
Or actually, I have found many different ways but non does what I want it to do.
First I tried to send over the link and script tags as strings inside a json object (with my other html code) and inserted them where I wanted them to be.
$('#main').children().remove();
$('#main').append(data.html);
$('body').append(data.js);
$('head').append(data.css);
it seems like this inserts them correctly when I 'inspect elements' and look under the 'sources' tab in the browser (chrome), but they don't execute/run.
Then, I tried to add id attributes to my css and js elements and then change the href and src attributes respectively (I have tried doing this both before and after my ajax call but both inside the click event). This allowed me to take away the css and js which belonged to the previous html code that was inserted in the div which is what I want.
$('#lessAjax').attr('href', 'location/style.less');
$('#jsAjax').attr('src','location/main.js');
and they are also included when I 'inspect elements' and look under the 'sources' tab in the browser (chrome), but obviously they don't execute/run either since this is pretty much the same thing as I did in the first example (only that now the code which is not used in my new view is taken away).
I then thought I had found a solution to the js file after finding the $.getScript() method since it executed my script which is directly under $(document).ready(function(){....}, but I noticed that the file cannot be found anywhere when I 'inspect elements' or when look under the 'sources' tab in the browser (chrome) so there is no way to take away or debug the code.
I have also tried
$('<link href="location/style.less" type="text/css" rel="stylesheet/less">')
.appendTo("head");
which includes the file but doesn't execute/run/work either.
I don't want to just include css and js code within script and style tags. I want to be able to switch css and js files as I change html code inside this div with Ajax (jQuery).
I have tried many more things in the 5 hours I spent trying to do this but I can't remember them all now. Surely this must be a common thing to do? Or are there any reasons for why I really shouldn't do this?
Any help would be much appreciated.
jqueryMobile: How to load external Javascripts
Can I load external stylesheets on request?
However please consider using a templating engine for content like this. There are many out there like underscoreJS and even frameworks that support them like Knockout, AngularJS and Backbone.
$("#somebutton").click(function(){
var path = 'path to css';
$.ajax({
url: path,
type:'HEAD',
error: function()
{
alert("failure")
},
success: function(result)
{
alert("success")
}
});
})
How to extract the header and the footer from this page to insert it in another page?
I'm a bit confused because when I copy and paste the header div it never has the same structure and graphics in the new page? Am I missing something here?
Typically when you copy/paste the div you're getting the HTML, but not the CSS styling (unless the styling is in-line).
There is a Chrome extension called "CSS + HTML" that allows you to, in the developer console, generate a version of the div that has all CSS turned into in-line CSS, so that you can copy/paste a pretty accurate version.
(Caveats: I've had some issues with the extension, so I don't enable it except when I need it, and the HTML produced is a) awful, because it has lots of unnecessary inline CSS, and b) not always a precise match. But it's pretty good.)
Yes, you are missing something. The CSS, images, and links... They are using relative links. You would need to be sure to replace those links.
The images are linked relatively so unless you copy them local you will not have access to them.
You would also need the Style Sheets as they are linked relatively in the head.
Not that the links in some cases are to .php files. Unless you know the php running in the background you are going to lose that functionality too.
I'm currently building a 6 page site and have finished the template for the navigation elements, the problem is, I just put the css & js into external files for the elements that will be the same on each page but now they aren't rendering on the original page or the new page, just showing white where there should be images.
Is this because I used id's on the elements instead of classes?
I thought it wouldn't matter if the id's were on separate pages that's why I'm asking here as it could be something else.
After putting the CSS & JS into external files Dreamweaver asked if I would like to update the links, I answered yes and it changed all background images in the external css file from (images/image.jpg) to (file:///images/image.jpg), I had to change them all back to the original path. Problem solved.
It does not matter if id's are on sepereate pages. You probably have a JS error somewhere in your migration. Did you load the page with firebug/chromedevelopertools/iedevelopertools open and see if there is a JS error?
ID are not the problem. check that the relative path is still correct according to the css file. to me that seems to be the most probable mistake.