TinyMCE setAttribute href
Spent quite some time trying to make a little extension to the wysiwyg editor TinyMCE to upload and link to files in a page. I was trying to use element.setAttribute('href',link); but it for the life of me wouldn't work right. The entire scenario:
You could insert a link without problems.
getAttribute worked perfectly
element.innerHTML = 'something'; worked perfectly to change what is between <a href="url"> and </a>
element.setAttribute('href',url); worked only on newly inserted (i.e. non saved) links but NOT on links that were set prior to opening the editor (again). It seemed to work because when opening the dialog getAttribute would give the updated link but the html source editor showed the old link and the old link was saved.
I kept at it and googled around and finally I found this post by diederickh on the TinyMCE forums. It had the answer! This is the current working code:
element.setAttribute("href","#");
element.setAttribute("class","load_category_content");
element.setAttribute("mce_href",name);
element.setAttribute("href", name);
inst.repaint();
Thanks so much to the poster, I couldn't have figured this out otherwise. I hope this post will help others in turn.
