4

i don't face this problem while working on localhost only when I access the page using the ip address of my system this happens and it only happens with IE!! (works on all other browsers)

by the way i'm using Tomcat V6.0.0.29, IE8

I tried debugging the JS code using IE developer tools debugger, ofcourse when I open using http://localhost:8080/ everything works perfectly fine, but when I use http://myIP:8080/ this loop is giving a problem :-

$('#someId > div').each(function(){...}); 

As in this loop doesn't run at all, it just kind of skips it. I have checked the IDs they are fine moreover its working in localhost why should it give a problem when I access it using my IP?

Note :- a. (correction) The problem is only there in IE7, it works perfectly in IE8.

b. As it turns out something weird is happening! i'm using IE8 when i open this webpage using localhost the developer tools shows its working in IE8 standards but when i use the IP address to access this page the developer tools shows its working in IE7 standards. When i changed the standards to IE8 it worked (using the IP address)!

c. But the problem is why the hell is it not working with IE7!! As in everything works except the loop mentioned above.

pranky64
  • 437
  • 3
  • 18
  • What's the error you get? I don't see anything wrong in this piece of code? Do you got more code? – Niels Nov 22 '11 at 07:56
  • Do you make any dynamic url / image reloading or stuff like that in your .each function? – Grrbrr404 Nov 22 '11 at 07:56
  • What is the code inside of each function? – Goran Obradovic Nov 22 '11 at 07:56
  • there are no ajax or image reloading stuff calls in this function the only thing this function does is it takes the content of each div and does some operations on it... The control doesn't even enter this loop when using IE and accessing using my ip address – pranky64 Nov 22 '11 at 07:59
  • add alert($('#someId > div').size()) to be sure that selector does not work when on ip – Goran Obradovic Nov 22 '11 at 08:00
  • @GoranObradovic okay i'll try this n tell u – pranky64 Nov 22 '11 at 08:04
  • @Niels there is no error as such! the browser doens't show any errors, it just doesn't run this loop!! – pranky64 Nov 22 '11 at 08:07
  • @pranky64 where are you loading jquery library from? from your localhost? google? – Grrbrr404 Nov 22 '11 at 08:11
  • @GoranObradovic : its actually showing 0 in IE! but i'm not able to understand why this should happen cause the same thing works perfectly in localhost!!! As some one had answered try clearing out the cache etc i have tried that too – pranky64 Nov 22 '11 at 08:12
  • From what i understand n i've read i think the problem might be because of tomcat, i'm trying to configure apache web server i hope(somehow) it works there :P – pranky64 Nov 22 '11 at 08:13
  • @GoranObradovic from localhost. – pranky64 Nov 22 '11 at 08:14
  • @pranky64 Well ok than forget my question about the loading location of jquey - seems to be ok. Could it be true that your div is located in a iframe or dynamically loaded with ajax? – Grrbrr404 Nov 22 '11 at 08:14
  • @Grrbrr404 yeah its kind of a iframe as in my entire page opens as a popup using an ajax request. The script inside the $(document).ready(..) work fine. even the events i have linked using the .live as in mouseover etc etc work fine – pranky64 Nov 22 '11 at 08:19
  • @pranky64 Hm ~ i wonder if this could be a reason for your problem. What is the content of your iframe src attribute? Maybe the reference is not optimal. Of course im not sure with this, just an idea – Grrbrr404 Nov 22 '11 at 08:36
  • @Grrbrr404 : i tried giving the url as "${pageContext.request.contextPath}/mypage.htm" instead of "/mypage.htm" which i had earlier given but both return the same result :( .... its sad, i'm stuck with this problem since yesterday!!!...i was supposed to make this code live yesterday!! – pranky64 Nov 22 '11 at 09:27
  • @pranky64 yeah i know web development can be a nightmare :) I am some how very sure that the problem comes up because of the iframe / popup. You could try to implement the html code of your dynamic page that is loaded via iframe into your mainpage and then execute your javascript. Just for testing reasons to make sure it is a iframe related problem or not - Understand? :) Regards – Grrbrr404 Nov 22 '11 at 09:38
  • @Grrbrr404 k i'll try that!! i tried using apache web server 2.2 though maybe its tomcat that causing the trouble but the problem remains!! ......so i guess i'll try what ur saying now :P – pranky64 Nov 22 '11 at 09:46
  • 1
    @Grrbrr404 : i tried accessing that page directly by giving the URL (instead of opening it in a popup) but again the same problem!! i did something like this : http://myIp/mypage.htm?param=2. Is it possible that maybe some div in my page isn't closed properly which might be causing this problem? cause there r lots of them, but if this was the problem shouldn't it have come up when i try opening the page using localhost? cause it works fine in localhost n this sucks!!!...... (i hope this is not the end of my web dev career :P) – pranky64 Nov 22 '11 at 10:07
  • @pranky64 yeah it could be true that some of your divs are malformed ... but i dont have a clue why your ip / hostname should make any difference here ... can you please copy your generated content (all divs) into http://jsfiddle.net/ and share the link with me? Maybe i can see e missing ', " , < or > sign. But to be honest ... that should not explain the difference between your ip and hostname :S – Grrbrr404 Nov 22 '11 at 10:13
  • @Grrbrr404 sorry can't upload the code :( i'm using a html validator to check the generated html to check for any problems with the divs lets see what happens....will post if i figure out a solution or the problem :P but i agree with u if malformed divs was a problem then it shouldn't have even worked when accessing using localhost !! – pranky64 Nov 22 '11 at 12:04

4 Answers4

2

Finally i came to know what was causing the problem in IE7. Consider the below situation:-

<div id="div1">abc
          <div id="div2">def
                   <div>hjs</div>
                   <div>zyx</div>
          </div>
          <div id="div3">xsj
                   <div>ask</div>
                   <div>iue</div>
          </div>
</div>

The jquery i had written for traversing these divs was something like

$("#divId > div").each(function(){..});

Now for the first level div that is traversing the divs directly inside the div with id "div1" worked perfectly in IE7, but when i did something like:-

$("#div2 > div").each(function(){..});

This worked in all browsers (even in IE8!!) but not in IE7. This is because apparently IE7 requires the exact child selector for divs. So for IE7 something like this needs to be written:-

$("#div1 > #div2 > div").each(function(){..});

for traversing the divs inside the div with id "div2"

So the problem was cause just by my lack of knowledge about IE7!! sorry n thanks guys!

pranky64
  • 437
  • 3
  • 18
1

The culprit being IE it could turn out something as evil as the browser not caching the page when loaded from localhost, but reading it from cache when using the ip. Make sure you load the page to empty cache from your ip.

JNissi
  • 1,120
  • 9
  • 22
  • i have tried all that deleting the cache/history/cookies etc etc and i tried accessing the same from someone else's system it gives the same problem!! – pranky64 Nov 22 '11 at 08:03
0

This may due to the group policy of your company for forcing Intranet sites using a specific version of IE in compatibility mode. I experienced exactly the same issue when I introducing some IE10+ Javascript libraries to my page.

IE Compatibility View Settings

To work around this you can either ask your company IT for changing the policy or force the browser to not using a compatibility view with the following tag.

<meta http-equiv="X-UA-Compatible" content="IE=Edge" />

More details for this tag can be found with the topic below.

StackOverflow - Force IE compatibility mode off using tags

Community
  • 1
  • 1
Conan
  • 355
  • 1
  • 4
  • 11
0

Check to see if your script is loaded when using your IP address. Sometimes browsers don't load scripts on special situations (for example when you want to load a script from an http source into an https page). Also you should check IE's security configuration.
To check whether your script is loaded and executed or not, simply put an alert('loaded') statement at the beginning of your code.

Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
  • 1
    the script loads because i'm able to debug it using IE developer tools(As mentioned in the question) and alerts are also working!!! – pranky64 Nov 22 '11 at 08:00