www.webdeveloper.com
Results 1 to 8 of 8

Thread: designmode cursor position

  1. #1
    Join Date
    Feb 2007
    Posts
    21

    designmode cursor position

    Hi,

    Is anyone here familiar with browser iframe / designmode operations?

    I have a designmode page that ideally should support preset fontstyles. So depending on the selected preset, the initial iframe contents with no text yet could, for example, be:

    Code:
    <font color="#000"><font face="Verdana">&nbsp;</font></Font>
    But depending on the browser, when you click in the iframe and start typing, the above style is not necessarily applied. What I am trying to figure out is how you can automatically set the cursor so it is positioned between the Font tags at &nbsp; so the style is actually applied to the entered text.

    Anyone knows how to do that?

    Thanks,
    Raoul

  2. #2
    Join Date
    Feb 2007
    Posts
    21
    Just to add, I meant how to set the cursor to this position when the iframe gets focus:

    Code:
    document.addEventListener ("focus", function (e) {
    
    ...
    
    }, true);

  3. #3
    Join Date
    Mar 2012
    Posts
    1,512
    The <font> tag is not supported in HTML5, and your syntax is wrong anyway. Use CSS styling instead. What has it got to do with IFrames, or getting focus?

  4. #4
    Join Date
    May 2014
    Posts
    911
    No clue what "designmode" means, though it reeks of WYSIWYG nonsense which is automatically rubbish markup and how not to build a website -- something that those ugly FONT tags that have no business on any website written after 1997 more than proves.

    Not sure what you're trying to do, but it sounds bad... Really bad... as in pitch it in the trash, learn some HTML and forget whatever it is you are trying to do bad. Sorry if that sounds harsh, but the truth most always is. That one little code snippet filled with FONT tags alone screams it loud and clear as yes, it's THAT bad.
    Java is to JavaScript as Ham is to Hamburger.

  5. #5
    Join Date
    Mar 2012
    Posts
    1,512
    Thinking about it, I guess that you are writing your own CMS, or something like that? Perhaps a greetings card creator that others can use? If so, I'd respectfully suggest that you need to be proficient in HML and CSS. If that snippet of code is representative of your current level of expertise, you may have a long way to go!

    I'd also suggest leaving JavaScript alone for the time being. Why? Because, if you do not know HTML and CSS thoroughly, it's easy to fall into bad habits of using JS and frameworks unnecessarily to do things that are better done in HTML and/or CSS.

  6. #6
    Join Date
    Feb 2007
    Posts
    21
    Yes jedaisoul, this is some sort of a CMS system. I guess I did not explain myself very well.

    This is a system that will allow the user to create contents for webpages.

    @deathshadow: Designmode: window.frames['wysiwyg'+el].document.designMode = "On";

    Are you unfamiliar with this? Is this ancient coding?

    @jedaisoul, Do you mean the snippet of code in my first or second post? The one in the first snippet is what the browsers generate when using the various document.execCommand() options. I know css is the way to go but FONT tag code is what the browsers still seem to generate when using document.execCommand() to change Font styles.

    I am involved in this since 1999. Nowadays I do more 3D development so all this might actually be outdated. Putting designmode on for browsers and using document.execCommand() to change fontstyle used to be the way to go for those HTML type of browser based email clients (and for example this webdeveloper forum post system) etc... the textarea is replaced for an iframe and designmode is turned on for the iframe. FCKeditor is one of the more popular WYSIWYG editors.

    Both comments make me feel stupid, is this no longer how this Works? Is there another way to do this now?

    @deathshadow, if you would have to make a content editable cross browser WYSIWYG system, how would you do that if I may ask?

    Thanks,
    Last edited by safra; 08-27-2014 at 02:57 AM.

  7. #7
    Join Date
    May 2014
    Posts
    911
    Quote Originally Posted by safra View Post
    @deathshadow: Designmode: window.frames['wysiwyg'+el].document.designMode = "On";

    Are you unfamiliar with this? Is this ancient coding?
    Ok, appears to be an IE 6 vendor specific JS property, that has somehow wormed it's way into the WhatWG's "living document" HTML5 spec, but not the actual JS specification. (... and that's why this "living document" garbage is turning into a confusing train wreck that has no business being called a specification).

    Interesting, it forces contentEditable onto all elements in the document. I'm vaguely aware of contentEditable, in that it's something I'd never allow on a website in the first place.

    Quote Originally Posted by safra View Post
    I know css is the way to go but FONT tag code is what the browsers still seem to generate when using document.execCommand() to change Font styles.
    ... and there's a significant portion of WHY I'd never use that on a website... or document.execCommand for that matter; especially since the useful parts (copy and paste) are disabled by default and have to be manually enabled in a user.js file.

    Quote Originally Posted by safra View Post
    @deathshadow, if you would have to make a content editable cross browser WYSIWYG system, how would you do that if I may ask?
    I wouldn't... they piss me off; they vomit up inaccessible buggy broken rubbish markup that has no business on any website written after 1997 -- and are a contributor what makes me BLOCK scripting on websites. I'd sooner eat a bullet; there's a reason you shouldn't use WYSIWYGs for back end design, as it's even WORSE that the whole "screwing around in a paint program like Photoshop or Fireworks and calling it web design" idiocy.

    By its very nature the mere notion of a WYSIWYG for anything web related is nonsense, since HTML's job is to say what things ARE, NOT what they look like. The only thing you can be guaranteed of on the web is that "what you see is not what everyone else gets"; It's also why things like forums usually use BBCode instead of HTML.

    Lands sake, when it comes to user input -- like on a forums -- if users send HTML I'd be specialchars blocking it and/or running strip_tags on it because you can't trust users to be allowed to do that; and that's pretty much industry standard practice; pretty much defeating the point of "contentEditable" or that parent "designMode" thing. That's just security 101; ALL user input is suspect. That's why bbCode EXISTS.

    You also mentioned e-mails when I use the presence of HTML as one of my spam filters, since no legitimate e-mail I would expect to get has any reason to even have HTML in it! HTML-only, right to the junk folder. Multi-part alternative HTML + "Text only", show the text-only.

    Maybe, MAYBE I'd allow it on the back-end of a CMS; I've used FCKEditor in the past though I've soured on it since it dropped the F and has gone all weird on us; used to be lean, mean, fast and efficient even if it did vomit up re-re markup -- now it's a bloated train wreck akin to all the other bloated manure being smeared all over websites like jQuery, Mootools, Bootcrap, etc, etc...

    Of course you also mention IFRAMEs which we were told for over a decade to stop using for them being inaccessible trash and redundant to the more secure OBJECT tag, which of course is why instead of riding Microsoft's ass about their broken OBJECT implementation IFRAMES are now magically back in, less secure, as are other redundancies like EMBED suddenly allowed and all new halfwit redundancies like AUDIO and VIDEO introduced... It's why to me HTML 5 looks more like the worst of pre-STRICT coding practices and seems carefully crafted for the people who still vomit up HTML 3.2, and until recently were slapping 4 tranny on it. Now they get to wrap 5 lip-service around the same outdated inaccessible rubbish practices and call it "modern" and "the future"

    ... RIGHT!
    Last edited by deathshadow; 08-27-2014 at 07:38 AM.
    Java is to JavaScript as Ham is to Hamburger.

  8. #8
    Join Date
    Feb 2007
    Posts
    21
    Thanks deathshadow for your constructive response...

    There are a lot of things I also do not like, unfortunately people do have expectations nowadays and like to be able to do certain things. I don't think we are doing ourselves a favor ignoring that hence our attempt to come up with a solution for this.

    We only need this for text areas (bold, italic, font style, size, color and links), are you saying there are good solid opensource bbcode libraries (I will do a search myself), userfriendly for non webdevelopers, which will also cross browser deal with my initial question ? And indeed ideally also handle copy /paste from other sources?
    Last edited by safra; 08-27-2014 at 12:10 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles