Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of sizset and sizcache attributes from jQuery?

I am already aware of what sizcache and sizset attributes are, but my concern is about their multiplication in our web application. I explain : We developed a "home brewed" WYSIWYG html editor using jQuery and when our users save the result HTML, we retrieve it with .html() (or innerHTML) and then save it in the database. Then our users can edit it, and save back again in the database. When using non-IE browsers, everything is fine, BUT in IE, jQuery adds those (ahemm nasty) sizset and sizcache attributes and they end up in the resulting HTML. When reloading HTML from the database and saving again, more and more sizset and sizcache are added.

The ideal solution for me would be that these attributes never end up in the database. I'm not sure I want to parse HTML server side to remove them if there is a solution from jQuery in the first place. Anyone ever faced this issue ?

Here's an example of what we have :

HTML :

<div id="source">
  <div sizset="37" sizcache09734513102453994="3" sizcache07081295255533577="350" sizcache0714455993494169="6324"></div>
  ... more html going on
</div>

Javascript :

var source = $('#source').html();

Variable "source" end up with sizset and sizcache attributes in it

like image 663
MaxiWheat Avatar asked Oct 06 '22 22:10

MaxiWheat


2 Answers

Use a regular expression on the entire string after you retrieve it using .html():

var re = /\s*(sizset|sizcache)\d*="[^"]*"/gi;
source = source.replace(re,'');

http://jsfiddle.net/mblase75/fMdVc/

Alternatively, jQuery has a .removeAttr() method, but you'll have to apply it to specific tags:

jQobj.removeAttr('sizset').removeAttr('sizcache');
like image 175
Blazemonger Avatar answered Oct 10 '22 03:10

Blazemonger


I recently moved a website to a new server running IIS 6. All of sudden, Header block of the web pages are inserted a meta tag <META content="IE=7.0000" http-equiv="X-UA-Compatible">, and sizset and sizcache attributes are everywhere under IE browser. Then I looked at IIS 6 settings, found that there's a custom http header settings for emulating IE7 there that forces its way to client(IE). After deleted that settings, everything goes back to normal with my IE10 browser.

like image 44
doug Avatar answered Oct 10 '22 01:10

doug