SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Open content in a div tag

    I use this code to open a link inside a specific div tag:

    Code:
    <a href="javascript:void(0);" onclick="loadExternalContentmypage();">My page</a>
    with this function:

    Code:
    function loadExternalContentmypage() {
            jQuery('#content').load("mypage.html");
        }
    This code wil open mypage.html in my div tag with a ID of #content.
    The code works fine in firefox and IE, but dosent work in chrome.
    Anyone have a suggestion?
    or perhaps some other javacode i should use?

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Are you working locally without a server? If you are you will need to setup a local server as jQuery requires a same domain policy to exist which file:/// paths don't offer.
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle

  3. #3
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I uploaded the code to the server and it did work. But actually it worked on my local computer as well, somehow just not for crome.

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2011
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello darkloshean,

    Just a small tryout, check if the function loadExternalContentmypage() gets called in chrome or not? This might help to trace till were the code is getting executed properly.
    PHP Programming Its more than just writing code

  5. #5
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,312
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by darkloshean View Post
    I uploaded the code to the server and it did work. But actually it worked on my local computer as well, somehow just not for crome.
    Chrome has a same origin policy which blocks this functionality locally, i.e. when testing on your PC without a server running.
    You can circumvent this by starting the browser with the following flags: the --disable-web-security.
    Here's a more in-depth explanation: http://stackoverflow.com/questions/3...-origin-policy

  6. #6
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, thats sound's like it thanks.


Bookmarks

Posting Permissions

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