This can now be done in Chrome, Safari, Firefox 4+, and Internet Explorer 10pp4+!
See this question's answer for more information:
Updating address bar with new URL without hash or reloading the page
Example:
function processAjaxData(response, urlPath){
document.getElementById("content").innerHTML = response.html;
document.title = response.pageTitle;
window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath);
}
You can then use window.onpopstate
to detect the back/forward button navigation:
window.onpopstate = function(e){
if(e.state){
document.getElementById("content").innerHTML = e.state.html;
document.title = e.state.pageTitle;
}
};
For a more in-depth look at manipulating browser history, see this MDN article.
The problem is caused by jQuery not understanding the !important
attribute, and as such fails to apply the rule.
You might be able to work around that problem, and apply the rule by referring to it, via addClass()
:
.importantRule { width: 100px !important; }
$('#elem').addClass('importantRule');
Or by using attr()
:
$('#elem').attr('style', 'width: 100px !important');
The latter approach would unset any previously set in-line style rules, though. So use with care.
Of course, there's a good argument that @Nick Craver's method is easier/wiser.
The above, attr()
approach modified slightly to preserve the original style
string/properties, and modified as suggested by falko in a comment:
$('#elem').attr('style', function(i,s) { return (s || '') + 'width: 100px !important;' });
Best Solution
Minifiers,obfuscators and compressors have been designed to solve the issue of downloading external elements when loading a page. They were never meant to be used for inline JavaScript or CSS since lots of that is normally kept outside of the page in a separate file.
Since you should be gzipping as much as you can, for browsers that can handle gzip, it shouldn't in reality matter that your inline css/javascript isn't minified on the page.