vForums Support > Programming & Coding :: Programming Discussion :: > IE = Facepalm

IE = Facepalm - Posted By Marc (cr0w) on 28th Apr 10 at 3:12pm
So, I was working on one of my sites yesterday, and decided to add UBBC buttons to the posting page. I began this project at about 11am. By noon, it was working nicely in FF/Chrome/Opera/Safari; even had an image uploader / advanced link maker in it.

Then...IE.

Let's just say by 5pm I had given up. Pretty much, the problem is that it keeps giving me "Unknown Runtime" errors whenever I try to use "innerHTML =" ("+=" works fine, though), forcing me to use DOM (which, funny enough, IE also doesn't do properly, and as such it's STILL not working).

Oh, and did I mention that I'm using "innerHTML = " a few hundred other times throughout the site with no issues?

*Sigh* I really wish Microsoft would just give up on the whole web browser thing and ship Firefox with Windows... {Sad}

Re: IE = Facepalm - Posted By Michael (wrighty) on 28th Apr 10 at 3:15pm
Let us have a look? {Cheesy}

Re: IE = Facepalm - Posted By Nick (nickb) on 28th Apr 10 at 4:37pm
^what he said! {Smile}

and I agree ms should drop ie or at least give us the choice to choose a default browser.

Re: IE = Facepalm - Posted By Marc (cr0w) on 28th Apr 10 at 9:23pm
 
^what he said! {Smile}

and I agree ms should drop ie or at least give us the choice to choose a default browser.


They do (at least for the past few months) give the option, but the problem is most users who aren't very tech-savvy will be too wary of using a different browser when IE works fine for what they use the internet for.

Oh, and here's how my code ended up after hours and hours of war with IE...it might make your eyes bleed, but again, IE's fault; it used to be pretty. {Sad}

Code:
 
  1. function add_ubbc(sTag,eTag)
  2. {
  3.     var pBox = document.pForm.body;
  4.     pBox.focus();
  5.  
  6.     if(typeof(pBox.selectionStart) != "undefined")
  7.     {
  8.         if(pBox.value)
  9.         {
  10.             var before = pBox.value.substr(0, pBox.selectionStart);
  11.             var curr = pBox.value.substr(pBox.selectionStart, (pBox.selectionEnd - pBox.selectionStart));
  12.             var after = pBox.value.substr(pBox.selectionEnd);
  13.  
  14.             pBox.value = before + sTag + curr + eTag + after;
  15.         }
  16.         else
  17.         {
  18.             var before = pBox.innerHTML.substr(0, pBox.selectionStart);
  19.             var curr = pBox.innerHTML.substr(pBox.selectionStart, (pBox.selectionEnd - pBox.selectionStart));
  20.             var after = pBox.innerHTML.substr(pBox.selectionEnd);
  21.  
  22.             pBox.innerHTML = before + sTag + curr + eTag + after;
  23.         }
  24.     }
  25.     else
  26.     {
  27.         alert("Internet Explorer is stupid.\r\nI spent 6 hours trying to get this to work right, but IE won\'t play along.\r\nSo I\'ll get these working later.\r\nThe last 2 buttons work, though.");
  28.         return;
  29.         if (window.getSelection)
  30.         {
  31.             if(pBox.value)
  32.             {
  33.                 pBox.value = pBox.value.replace(window.getSelection(), sTag + window.getSelection() + eTag);
  34.             }
  35.             else
  36.             {
  37.                 pBox.innerHTML = pBox.innerHTML.replace(window.getSelection(), sTag + window.getSelection() + eTag);
  38.             }
  39.         }
  40.         else if (document.getSelection)
  41.         {
  42.             if(pBox.value)
  43.             {
  44.                 pBox.value = pBox.value.replace(document.getSelection(), sTag + document.getSelection() + eTag);
  45.             }
  46.             else
  47.             {
  48.                 pBox.innerHTML = pBox.innerHTML.replace(document.getSelection(), sTag + document.getSelection() + eTag);
  49.             }
  50.         }
  51.         else if (document.selection)
  52.         {
  53.             if(pBox.value)
  54.             {
  55.                 pBox.value = pBox.value.replace(document.selection.createRange(), sTag + document.selection.createRange() + eTag);
  56.             }
  57.             else
  58.             {
  59.                 var nBox = document.createElement("textarea");
  60.                 nBox.name = "body";
  61.                 nBox.style.width = "400px";
  62.                 nBox.style.height = "150px";
  63.  
  64.                 nBox.innerHTML = pBox.innerHTML.replace(document.selection.createRange(), sTag + document.selection.createRange() + eTag);
  65.  
  66.                 document.getElementById("txtBody").removeChild(document.getElementById("txtBody").firstChild);
  67.                 document.getElementById("txtBody").appendChild(nBox);
  68.             }
  69.         }
  70.         else
  71.         {
  72.             return "";
  73.         }
  74.     }
  75.  
  76.     pBox.focus();
  77. }
 


EDIT: Rossy, the code tags are deleting half of my code? {Sad} (just quote the post if you wish to see the actual code for now)

EDIT 2: The smilies are also being weird. {Shocked}

Edit 3 by Ross: Not the code tags fault. More just the templating system. Have put in a fix so the message contents don't get run through it {Tongue Out}