2

I have the following javascript code in a HTML document which loads Html in a div:

<script> $(function(){ $("#submenu a").click(function(){ var page = this.hash.substr(1); $.get(page+".html",function(gotHtml){ $("#contenedorprincipal").html(gotHtml); }) }); }); </script> 

In Firefox it runs perfectly, but in Chrome and IE it does not work. Any ideas or suggestions?

4
  • Do you get an error? I suspect the hash property is not implemented in Chrome/IE... Commented Apr 29, 2012 at 21:23
  • what doesn't work ? What results do you expect ? What results do you have ? Can you paste the related HTML code ? Commented Apr 29, 2012 at 21:25
  • It would be better if you could write a more descriptive title, and give a bit more information including the html and a description about what is actually going wrong. It can often help to create a live example to go along with your question using something like jsfiddle.net or provide a url to your site. @gdoron: You could have been a little more helpful to the first time poster instead of being sarcastic. Commented Apr 29, 2012 at 21:26
  • Sorry, maybe I should give you more info about the problem. Is my first time, thanks for the comments. Commented Apr 29, 2012 at 22:33

2 Answers 2

2

seems to me like it works in chrome... any way try this: http://jsfiddle.net/8daxU/

replace the wrapping function with (I added an alert just to show the hash - remove at afterwords)

 $(document).ready(function(){ $("#submenu a").click(function(){ var page = this.hash.substr(1); alert(page); $("#contenedorprincipal").load(page+".html"); }); }); 
Sign up to request clarification or add additional context in comments.

8 Comments

Thanks Yaron for the Answer but Chrome seems not like something.. :( The alert works correctly but the html don't appear in div..
are you sure that you have the specific page in the same folder? take a look at the "network" tab in the developers tools of chrome to see if you can find the request and let us know what the response is
I've found the request URL in Chrome and... it's ok! I don't understand the reason why Chrome don't "paint" the html...
can you post some online link that we'll be able to investigate it ourselves?
I've found this in network tab of chrome: XMLHttpRequest cannot load, Origin null is not allowed by Access-Control-Allow-Origin...
|
0

This should work across browsers:

$(function () { var $content = $( '#contenedorprincipal' ); $( '#submenu' ).on( 'click', 'a', function ( e ) { $content.load( this.href.split( '#' )[1] + '.html' ); }); }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.