Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Load another site page into a DIV

  1. #1
    Join Date
    Dec 2012
    Location
    UK
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Load another site page into a DIV

    Hi there,

    I'm making my first site in a few years and have a sidebar menu and a content div. I am trying to have it so that if you click a menu link, the div contents are changed to whatever is in "home.php" or "about.php". When I used to make sites I'd wind up copying and remaking every page including the full-layout and the menu, but I really know that's not the way to go and I'm trying to focus on dynamic web development now.

    I'm still not too sure if this is the way to go about it but I've spent the past week learning the basics of PHP and MySQL and now it's looking like I'll need some jQuery/AJAX? Any threads mentioning this though jump too far into it. Am I supposed to use PHP, jQuery, JS, AND AJAX? I'm trying to use innerHTML with JS but it looks like this isn't the best way to do it - I also cant' find an innerHTML method that specifically would load "myPage.php" into my content div. I'm just wondering if I'm even doing this the right way? In terms of industry standards, what is the accepted way to dynamically load content these days for a site with a few pages built in Notepad++? I just want to make sure I'm starting off on the right foot as this is the field I'd like to go into. I'm good with the basics of HTML and CSS, I just haven't looked too much at this side of things before.


  2. #2
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    47
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    As far as I can tell, you're asking for something like this:
    http://www.dynamicdrive.com/dynamici...axtabscontent/
    Which can load content from other weboages.
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  3. #3
    Join Date
    Dec 2012
    Location
    UK
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by bernie1227 View Post
    As far as I can tell, you're asking for something like this:
    http://www.dynamicdrive.com/dynamici...axtabscontent/
    Which can load content from other weboages.
    Hi Bernie, I've tried this and had no luck unfortunately, just keeps opening in a new page. Do you happen to know what I would have left out in my code below?

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
    
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    
    <meta name="description" content="" />
    
    <meta name="keywords" content="" />
    
    <meta name="author" content="" />
    
    <link rel="stylesheet" type="text/css" href="style.css" media="screen" />
    
    <title>Nest</title>
    
    
    <script type="text/javascript">
    
    function updateContent(page){
        document.getElementById('content').innerHTML = "test";
    }
    
    
    
    var countries=new ddajaxtabs("countrytabs", "content")
    countries.setpersist(true)
    countries.setselectedClassTarget("link") //"link" or "linkparent"
    countries.init()
    
    </script>
    
    </head>
    
    	<body>
    
    		<div id="wrapper">
    			<div id="content">
    				content
    				<hr>
    				test
    				<?php
    					echo "Test";
    				?>
    				
    			</div> <!-- end #content -->
    
    			<div id="sidebar">
    				<div id="fixed">
    											
    						<ul id="countrytabs">
    							<li><a href="#" class="selected" rel="#default">Tab 1</a></li>
    							<li><a href="home.php" rel="content">Tab 2</a></li>
    							<li><a href="about.php" rel="content">Tab 3</a></li>
    							</ul>
    				
    				<br />
    				my shoutbox will go here
    				</div>
    			</div> <!-- end #sidebar -->
    		</div> <!-- End #wrapper -->
    
    	</body>
    
    </html>

    Thanks very much for your help.

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    2,011
    Thanks
    16
    Thanked 315 Times in 313 Posts
    Blog Entries
    13

    Default

    That's a great script.

    I also think you can pretty much accomplish what you want with php and the include() command too.

    Picture this; you *could* have all your HTML, Upto the opening content <div> tag, stored in a common header file (this could include the DOCTYPE, <head> section opening <body> tag and menu etc), and then everything from the closing </div> tag could be stored in a common footer file (the footer bar and closing </body> and </html> tag). Everything in the middle would be the differing content for each particular page.

    It would be like breaking your pages into jigsaw pieces - the header and footer file would be jigsaw pieces that you use on every page, so when you make a change, you only edit one file and the change reflects site-wide. The content however, would be specific to each page, so all of your pages could be laid our like this;

    Code:
    <?php include('header.html');?>
    
    <!-- page content HTML here -->
    <p>Hello. This the some information about me. </p>
    
    <?php include('footer.html');?>
    - here's a tutorial that will hopefully help http://www.tizag.com/phpT/include.php
    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

  5. #5
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,382
    Thanks
    31
    Thanked 148 Times in 142 Posts
    Blog Entries
    34

    Default

    There are many ways to accomplish what you want. Here's one way. Experiment with it. I used html files:
    index.html:
    <!doctype html>
    <html >
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title></title>
    <script>window.location.replace('home.html')</script>
    </head>
    <body></body>
    </html>
    ---
    menu.html:
    <!doctype html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title></title>
    </head>
    <body>
    <div style="position: absolute; top: 0px; right: 0px; padding-top: 20px; width:200px; bottom:0px; background: #dedede; font-family: verdana; font-size:12px">
    <div style="position: relative; text-align: center">
    LOGO<br><br><br><br>
    <a href="home.html">HOME</a><br><br>
    <a href="about.html">ABOUT</a>
    </div>
    </div>
    </body>
    </html>
    ---
    menu.js:
    $('html').append("<iframe name='framename' src='menu.html' style='position:absolute; width:0px; height:0px; left:-10000px' ></iframe>")
    function include()
    {$('body').append(frames['framename'].document.documentElement.innerHTML)}
    window.onload=include
    ---
    home.html:
    <!doctype html>
    <html >
    <head>
    <title>HOME</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
    <script src="menu.js"></script>
    </head>
    <body>
    <div style="position: absolute; left: 0px; top: 0px; right:200px; bottom: 0px; padding:10px; font-family: verdana; font-size:12px; border:10px solid #dedede">
    THIS IS HOME.HTML
    <hr>
    CONTENT
    </div>
    </body>
    </html>
    ---
    about.html:
    <!doctype html>
    <html >
    <head>
    <title>ABOUT</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
    <script src="menu.js"></script>
    </head>
    <body>
    <div style="position: absolute; left: 0px; top: 0px; right:200px; bottom: 0px; padding:10px; font-family: verdana; font-size:12px; border:10px solid #dedede">
    THIS IS ABOUT.HTML
    <hr>
    CONTENT
    </div>
    </body>
    </html>
    ---
    Although menu.js uses innerHTML, the code you may want to put in menu.html will be preserved thanks to jquery.
    Arie.

  6. #6
    Join Date
    Dec 2012
    Location
    UK
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi - thanks very much for your replies I had tried something similar Beverlyh with include, but was just a bit fed up of copying and pasting and was wondering if there was a more dynamic approach? Is there perhaps a way to change <?php include('contentIWant.html');?> so it would update in place of the DIV?

    And thank you molendijk but I probably should have mentioned I wanted to avoid iframes A lecturer of ours heavily encouraged us to avoid them these days.

  7. #7
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    47
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    Any thoughts on the Ajax tabs script?
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  8. #8
    Join Date
    Dec 2012
    Location
    UK
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Bernie, I thought I'd replied but it looks like my post was held back for moderation for whatever reason? :/

    I tried it with the following code and had no joy:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
    
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    
    <meta name="description" content="" />
    
    <meta name="keywords" content="" />
    
    <meta name="author" content="" />
    
    <link rel="stylesheet" type="text/css" href="style.css" media="screen" />
    
    <title>my site</title>
    
    
    <script type="text/javascript">
    
    function updateContent(page){
        document.getElementById('content').innerHTML = "test";
    }
    
    var countries=new ddajaxtabs("countrytabs", "content")
    countries.setpersist(true)
    countries.setselectedClassTarget("link") //"link" or "linkparent"
    countries.init()
    
    </script>
    
    
    </head>
    
    	<body>
    <script src="jquery.js"></script>
    		<div id="wrapper">
    			<div id="content">
    				content
    				<hr>
    				test
    				<?php
    					echo "Test";
    				?>
    				
    			</div> <!-- end #content -->
    
    			<div id="sidebar">
    				<div id="fixed">
    										
    						<ul id="countrytabs">
    							<li><a href="#" class="selected" rel="#default">Tab 1</a></li>
    							<li><a href="home.php" rel="content">Tab 2</a></li>
    							<li><a href="about.php" rel="content">Tab 3</a></li>
    						</ul>
    				
    				<br />
    				my shoutbox will go here
    				</div>
    			</div> <!-- end #sidebar -->
    		</div> <!-- End #wrapper -->
    
    	</body>
    </html>
    And then it wasn't until I found this code snippet:
    Code:
    <DOCTYPE html>
    <html>
    <head>
    	<title>Example</title>
    	<meta charset="UTF-8"/>
    	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
    	<script>
    	$(function() {
    		$("#Menu > li a").each(function() {
    			var self = $(this);
    			var href = self.attr("href");
    			self.attr("href", "javascript: void(0);");
    			self.click(function() {
    				$("#Contents").load(href);
    			});
    		});
    	});
    	</script>
    </head>
    <body>
    	<h1>Select!</h1>
    	<ul id="Menu">
    		<li><a href="showInfo.php?id=1">First</a></li>
    		<li><a href="showInfo.php?id=2">Second</a></li>
    		<li><a href="showInfo.php?id=3">Third</a></li>
    	</ul>
    	<div id="Contents"></div>
    </body>
    </html>
    That I realised I'd left out
    Code:
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
    I guess I should definitely learn how to use Ajax then if I want to do anything useful in the web development world?

  9. #9
    Join Date
    Dec 2012
    Location
    UK
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Bernie, unfortunately any post I try to respond with including code is held back for moderation - I didn't realise this until there now, I thought my previous reply to you from about an hour ago had gone though :/ I tried your link however the links just kept opening in new browser windows - I had left out any reference to including a jQuery.min.js file, I had no idea this was needed as I'd never used it before! However the second post in this thread here let me know that I did indeed need to have that in - and that code actually works pretty well too. Thanks for your help, bit discouraging for new members though that posts containing code have to be approved D:

  10. #10
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    47
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    Sorry about it being held back for moderating, it must have been caught by the anti-spam filter.
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

Similar Threads

  1. Javascript - Load new images on each page load/refresh
    By spook_man in forum Looking for such a script or service
    Replies: 8
    Last Post: 12-11-2013, 12:31 AM
  2. DHTML Window widget - Load after page load?
    By davidjohny in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 10-21-2008, 08:36 AM
  3. Script has no name - sequential image load on page load
    By vkbarefoot in forum Looking for such a script or service
    Replies: 10
    Last Post: 07-24-2007, 04:28 PM
  4. How To Load Another Web Site into a DIV??
    By jlfximedia in forum JavaScript
    Replies: 1
    Last Post: 04-04-2006, 05:53 PM
  5. How To Load Another Web Site into a DIV??
    By jlfximedia in forum CSS
    Replies: 0
    Last Post: 04-03-2006, 03:16 PM

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
  •