jquery - Javascript bookmarklet, href breaks? -


i have been fretting on long time, , hoping knows problem , way fix it..

i generating bookmarklet , works perfectly, magically if may after many days of grinding butt off on mysql , php..

for example, please consider bookmarklet being generated.

javascript:(function(){ a=document.createelement('script'); a.setattribute('src','//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js'); document.body.appendchild(a); data='[["#txtapplicantlname","agrawal","text"],["#txtapplicantfname","aayush","text"],["#txtfather","ranjan","text"],["#txtmother","neelam","text"],["#txtpincode","452010","text"],["#txtphone","2147483647","text"],["#txtemail","aayush@mail.com","text"],["#rdosex_0,#rdosex_1","1","radio"]]'; for(a=$.parsejson(data),b=a.length-1;0<=b;b--){ c=a[b]; if (c[2] =='text') { $(c[0]).val(c[1]); } else if (c[2] == 'radio'){ rdata = c[0].split(','); rnum = c[1] - 1; select = rdata[rnum]; $(select).attr('checked', true); } } })(); 

it recreation of closure compiled bookmarklet, not able find original since never got saved(long story..)so figured might aswell edit closure compiled one. json file being inserted because bookmarklet has generated dynamically , destined run on https website , hence cant send out ajax calls..

anyways, code works when try insert hyperlink, breaks. if need be, code pretty goes this

"<a href=" + (code shown above) + "> drag me bookmarks bar!</a>" 

and breaks.. here source code being printed out if need be.

<span class='span6'>please drag following button bookmarks bar! <br>javascript:(function(){ a=document.createelement('script'); a.setattribute('src','//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js'); document.body.appendchild(a); data='[["#txtapplicantlname","agrawal","text"],["#txtapplicantfname","aayush","text"],["#txtfather","ranjan","text"],["#txtmother","neelam","text"],["#txtpincode","452010","text"],["#txtphone","2147483647","text"],["#txtemail","aayush@mail.com","text"],["#rdosex_0,#rdosex_1","1","radio"]]'; for(a=$.parsejson(data),b=a.length-1;0<=b;b--){ c=a[b]; if (c[2] =='text') { $(c[0]).val(c[1]); } else if (c[2] == 'radio'){ rdata = c[0].split(','); rnum = c[1] - 1; select = rdata[rnum]; $(select).attr('checked', true); } } })();<a href='javascript:(function(){ a=document.createelement('script'); a.setattribute('src','//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js'); document.body.appendchild(a); data='[["#txtapplicantlname","agrawal","text"],["#txtapplicantfname","aayush","text"],["#txtfather","ranjan","text"],["#txtmother","neelam","text"],["#txtpincode","452010","text"],["#txtphone","2147483647","text"],["#txtemail","aayush@mail.com","text"],["#rdosex_0,#rdosex_1","1","radio"]]'; for(a=$.parsejson(data),b=a.length-1;0<=b;b--){ c=a[b]; if (c[2] =='text') { $(c[0]).val(c[1]); } else if (c[2] == 'radio'){ rdata = c[0].split(','); rnum = c[1] - 1; select = rdata[rnum]; $(select).attr('checked', true); } } })();'>drag me!</a></span> 

it breaks on many levels have tried many times around it, each time make minor change breaks again. hoping more reliable solution , extremely thankful if can me..

edit: happened after escaping double quotes htmlspecialchars

<span class='span6'>please drag following button bookmarks bar! <br>javascript:(function(){ a=document.createelement('script'); a.setattribute('src','//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js'); document.body.appendchild(a); data='[["#txtapplicantlname","agrawal","text"],["#txtapplicantfname","aayush","text"],["#txtfather","ranjan","text"],["#txtmother","neelam","text"],["#txtpincode","452010","text"],["#txtphone","2147483647","text"],["#txtemail","aayush@mail.com","text"],["#rdosex_0,#rdosex_1","1","radio"]]'; for(a=$.parsejson(data),b=a.length-1;0<=b;b--){ c=a[b]; if (c[2] =='text') { $(c[0]).val(c[1]); } else if (c[2] == 'radio'){ rdata = c[0].split(','); rnum = c[1] - 1; select = rdata[rnum]; $(select).attr('checked', true); } } })();<a href='javascript:(function(){ a=document.createelement('script'); a.setattribute('src','//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js'); document.body.appendchild(a); data='[[&quot;#txtapplicantlname&quot;,&quot;agrawal&quot;,&quot;text&quot;],[&quot;#txtapplicantfname&quot;,&quot;aayush&quot;,&quot;text&quot;],[&quot;#txtfather&quot;,&quot;ranjan&quot;,&quot;text&quot;],[&quot;#txtmother&quot;,&quot;neelam&quot;,&quot;text&quot;],[&quot;#txtpincode&quot;,&quot;452010&quot;,&quot;text&quot;],[&quot;#txtphone&quot;,&quot;2147483647&quot;,&quot;text&quot;],[&quot;#txtemail&quot;,&quot;aayush@mail.com&quot;,&quot;text&quot;],[&quot;#rdosex_0,#rdosex_1&quot;,&quot;1&quot;,&quot;radio&quot;]]'; for(a=$.parsejson(data),b=a.length-1;0&lt;=b;b--){ c=a[b]; if (c[2] =='text') { $(c[0]).val(c[1]); } else if (c[2] == 'radio'){ rdata = c[0].split(','); rnum = c[1] - 1; select = rdata[rnum]; $(select).attr('checked', true); } } })();'>drag me!</a></span> 

please use

document.getelementsbytagname('head').item(0).appendchild(a); 

instead of use

document.body.appendchild(a);  

i hope work well.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -