Monday, 15 September 2014

javascript - What compatibility will I need to keep in mind for html data storing? -



javascript - What compatibility will I need to keep in mind for html data storing? -

according this question 1 can store info within html tags, doctype header following:

<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">

i wondering cross/backwards compatibility should maintain in mind of, versions of browsers have problems if tried using javascript access output-file attribute in form tag. e.g.

<form name="myform" id="myform" output-file="export.log">

edit: reason header adding onto existing intranet scheme , utilize same header every page , around before html5 (which ideally have wanted use)

edit 2: aware should utilize data- prefix attribute can utilize console.log(document.getelementbyid("myform").getattribute("output-file")) fine , right result, figure pick on , explain possible problems cross/backwards compatibility

why heck using transitional doc type? why not strict?

anyways - reply question, yes can utilize html storage, should syntax right:

<form name="myform" id="myform" data-output-file="export.log">

note utilize of data- prefix.

you can read in javascript with:

var el = document.getelementbyid("myform"); var filename = el.getattribute("data-output-file"); el.setattribute("data-output-file", "newname");

this first-class writeup: http://webdesign.tutsplus.com/tutorials/all-you-need-to-know-about-the-html5-data-attribute--webdesign-9642

edit

the utilize of data-* attributes supported in modern browsers, far ie. won't have compatibility issues there.

to reply other question: using data-* prefix you:

won't run issues new html attributes added later. html5 standard set aside data-* namespace purpose. in time, when <element>.dataset, you'll able utilize instead of hacky setattribute , getattribute.

edit 2

this method works way ie6. if not utilize data- prefix run risk of conflicts new html5 attributes come later.

javascript html

No comments:

Post a Comment