Reply
Changing contents of a DIV
Old 10-09-2007, 06:55 PM Changing contents of a DIV
Nathand's Avatar
Extreme Talker

Posts: 210
Location: USA
Is there a way that when I click on a link it will change the contents of a div to the contents of another page on my site? I tried:

Code:
<a href="#" onclick="javascript:document.getElementById('mainbody').innerHTML=./webpage.html">webpage</a>
But it didn't work.

Thanks,
Nathan
Nathand is offline
Reply With Quote
View Public Profile Visit Nathand's homepage!
 
When You Register, These Ads Go Away!
Old 10-09-2007, 07:00 PM Re: Changing contents of a DIV
coolkbk585's Avatar
Be good this Christmas!

Latest Blog Post:
KBlog has been deativated
Posts: 642
Name: Kyle
Location: Ada, MI
While it may not always be the best thing to do, you might want to use an iframe to do that. While it's not the newest technology, it would probably be the right way to go.

If you don't think so, then you should ask this again in the Javascript forum.
__________________
<?php if($Adsense_Revenue > 0): define('HAPPINES','100%'); else: define('HAPPINESS', '0%') endif; ?>
coolkbk585 is offline
Reply With Quote
View Public Profile Visit coolkbk585's homepage!
 
Old 10-10-2007, 02:43 PM Re: Changing contents of a DIV
Foundationflash's Avatar
Ultra Talker

Posts: 410
Name: Harry Burt
Location: Colchester, Essex, England
PHP could do it, but it wouldn't be that efficient. Other than that, IFrames probably are the way to go. I looked into this a lot myself about a year ago, and found it was a toss-up between PHP and IFrames. Some one else might know of something though.
__________________
Foundation Flash tutorials : www.foundation-flash.com

New Dreamed Up Web Design: www.dreamedupdesign.com
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Old 10-10-2007, 04:55 PM Re: Changing contents of a DIV
coolkbk585's Avatar
Be good this Christmas!

Latest Blog Post:
KBlog has been deativated
Posts: 642
Name: Kyle
Location: Ada, MI
You can't really request the content from another page to put into a div. You can make other HTML appear there, but it has to be in the Javascript on that page.
__________________
<?php if($Adsense_Revenue > 0): define('HAPPINES','100%'); else: define('HAPPINESS', '0%') endif; ?>
coolkbk585 is offline
Reply With Quote
View Public Profile Visit coolkbk585's homepage!
 
Old 10-10-2007, 06:49 PM Re: Changing contents of a DIV
ChipJohns's Avatar
I don't know! Do you?

Posts: 485
Name: Chip Johns
Location: Savannah Georgia
Can you give us some more information about what you are trying to accomplish; with a few more specifics? The more vague the question, The less beneficial the answer. If we know more we might be able to provide alternative solutions. (but, then, again ...!)
ChipJohns is offline
Reply With Quote
View Public Profile Visit ChipJohns's homepage!
 
Old 10-11-2007, 04:22 PM Re: Changing contents of a DIV
LadynRed's Avatar
Super Moderator

Posts: 6,699
Location: Tennessee
There IS away to do this !
http://www.aplus.co.yu/web-dev/inser...her-html-page/

No iframes but works like one.
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!
"Using or working with IE is like having to wear a 1970's polyester suit with pantyhose and a girdle, to work everyday"
Carolina Corvette Club
LadynRed is offline
Reply With Quote
View Public Profile
 
Old 10-14-2007, 10:11 AM Re: Changing contents of a DIV
Foundationflash's Avatar
Ultra Talker

Posts: 410
Name: Harry Burt
Location: Colchester, Essex, England
Well blow me down. I stand corrected.
__________________
Foundation Flash tutorials : www.foundation-flash.com

New Dreamed Up Web Design: www.dreamedupdesign.com
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Old 10-14-2007, 10:34 AM Re: Changing contents of a DIV
maxxximus's Avatar
Extreme Talker

Posts: 205
Name: Rob
Location: UK
I think there is an even more seemless method with no page reload - using Ajax. The js below should be linked to or embedded directly in the head.

The function can then be called by passing the URL of the page to be loaded (Whatever.html) within the anchor tag. <a href="#" onclick="ajaxFunction('Whatever.html');return false;" >link</a>
The function will load the contents of the page into a div with an id of 'include' but you can change it to whatever.

If your prepared to use js (there are a small % of users who dont enable it) then ajax will look better.

Code:
function ajaxFunction(a)
  {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
       document.getElementById('include').innerHTML=xmlHttp.responseText;
        }
      }
    xmlHttp.open("GET",a,true);
    xmlHttp.send(null);
  }
  function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

Last edited by maxxximus : 10-14-2007 at 10:37 AM.
maxxximus is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Changing contents of a DIV
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15071 seconds with 12 queries