Jump to content

Code doesn't work in IE.


Chocolate570

Recommended Posts

This really annoys me. My code works perfectly in Safari, FireFox (1.0-2.0), and Opera (8-9) but only IE fails the request and gives an error. Why me?Can someone please tell me what I'm doing wrong? The code is supposed to check if you are logged in on a forum and if you have posted already in the current topic. If you have, it goes through the body innerHTML and makes all of the stuff between the bbcode tags [hide] and [/hide] visible. If not, it makes them invisible. It works perfectly in every other browser, yet in IE...It either gives me an error that says something to the effect of"Internet explorer can not display the page requested."or, to my users, it gives the inbuilt alert message in my code that the AJAX request could not be completed.Test forum:z10.invisionfree.com/sweetcodingCodes:(header)

//Thank you very much Mozilla Docs//For providing help with this AJAX request.function ajReq(url) {  var aj = false;  if (window.XMLHttpRequest) { // FF & Moz & Saf    aj = new XMLHttpRequest();   }  else if (window.ActiveXObject) { // Guess.    try {                aj = new ActiveXObject("Msxml2.XMLHTTP");            } catch (e) {                try {                    aj = new ActiveXObject("Microsoft.XMLHTTP");                } catch (e) {}            }  }  //Uh oh! Browser doesn't support ajax.  if (!aj) {    alert('Error: Unable to create AJAX Request Object');    return false;  }  //Send request  aj.onreadystatechange = function() { compFun(aj); };  aj.open('GET', url, true);  aj.send(null);}function compFun(aj) {  if (aj.readyState == 4) {    if (aj.status == 200) {      rep(aj.responseText);    }     else {      alert('Error: AJAX request returned null! Please refresh the page. If the problem persists, contact an adminstrator.');     }  }}//This function takes the text, replaces it, and outputs "true" or "false" depending on whether the member has posted on the topic or not.function rep(text) {  //Check member number   //So I can reference it later in the script  repLa=document.getElementById("userlinks")  linkRa=repLa.getElementsByTagName("a");  for(i=0;i<linkRa.length;i++) {    if(linkRa[i].href.split('showuser=')[1]!=null) {      hlder=linkRa[i].href.split('showuser=')[1];    }  }  zoop=text.indexOf('showuser='+hlder);  if(zoop != (-1)) {     //Yippee! We got it! Now we have to 'unhide' the elements.    hold=document.getElementsByTagName("*");    for(y=0;y<hold.length;y++) {      if(hold[y].className.toLowerCase()=="hid") {        hold[y].style.visibility="visible"      }    }  }}

Footer:

/*///////////////////////////////////Hide stuff (images/text) if  ////User has not posting in      ////Topic. By Choco 2006.       ////No editing required.          /////////////////////////////////*///URL Splitters.//Procures topic num and board URL.winFirst=window.location.href;winNext=winFirst.split('index');boardU=winNext[0];topNext=winFirst.split('showtopic=');topNum=topNext[1]url=boardU+'index.php?s=&act=Stats&CODE=who&t='+topNum;cap=winFirst.split('act=Post')if(!cap[1]) {total=document.getElementsByTagName("body")for(z=0;z<total.length;z++) {  inHl=total[z].innerHTML;  test=inHl.indexOf("hide")  if(test!=(-1)) {      s = inHl.replace(/\[hide\]/g,"\<div class='hid'\>");      s = s.replace(/\[.hide\]/g,"\<\/div\>");  }}}document.body.innerHTML=s;ajReq(url)

Stylesheet:

.hid{visibility:hidden;}

Could anyone tell me what's wrong? It's pretty urgent.Thanks.Choco

Link to comment
Share on other sites

I checked the mozilla error console. There was only one error, and it was trivial. It said one of my variables wasn't defined. But that couldn't cause this error... could it? The variable was defined, except it was defined in a for loop. I dunno. There were no other errors.

Link to comment
Share on other sites

Dude do me a favor and put your CSS into one file... i had to spend a few minutes reading through all of your CSS on the page...your Javascript is very complex. at least for a simple AJAX request...Also i think this can be simplifiedif(test!=(-1)) {s = inHl.replace(/\[hide\]/g,"\<div class='hid'\>");s = s.replace(/\[.hide\]/g,"\<\/div\>");}if(test!==-1){s = inHl.replace(/\[hide\].\[\/hide\]/,"<div class=\"hid\">\\1</div>")//Mind you i dont know how javascript does its call back for matching }But yeah... im not sure your Javascript seems overly complex for something so simple...

Link to comment
Share on other sites

Well, let me run through it.

/*///////////////////////////////////Hide stuff (images/text) if ////User has not posting in ////Topic. By Choco 2006. ////No editing required. /////////////////////////////////*///URL Splitters.//Procures topic num and board URL. //This part is not really needed, as I could do this inline...but it makes//cleaner code.winFirst=window.location.href;winNext=winFirst.split('index');boardU=winNext[0];topNext=winFirst.split('showtopic=');topNum=topNext[1] //This is the topic number.url=boardU+'index.php?s=&act=Stats&CODE=who&t='+topNum;cap=winFirst.split('act=Post') //checks if you're posting. if so, don't replaceif(!cap[1]) {total=document.getElementsByTagName("body") //Gotta change the body.for(z=0;z<total.length;z++) {inHl=total[z].innerHTML;test=inHl.indexOf("hide") //Checks if we should search or not.if(test!=(-1)) {s = inHl.replace(/\[hide\]/g,"\<div class='hid'\>");s = s.replace(/\[.hide\]/g,"\<\/div\>");}}}document.body.innerHTML=s; //This might be the problem. IE doesn't like//this document.body.innerHTML.ajReq(url) //Run the ajax request and pass the URL for it to request to it.

And it's overly complex because I can't edit the main forum HTML. I can add on to it, but that's through a controlled space. And to edit the main forum, I have to use javascript matching to retrieve elements and then make changes. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...