Results 1 to 8 of 8

Thread: swapDIV on a Different Page

  1. #1
    Join Date
    Feb 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default swapDIV on a Different Page

    This is my first post, and I'm no pro when it comes to writing scripts.
    Ok, what I need to do is change, (swapDIV), on PAGE 2, and I need to do this from PAGE 1, using JavaScript and CSS. I need to do this without using a Button, it needs to be a text link. I'm not using jQuery either so I prefer not to use it.
    In Advance, Thanks.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Can you give more information or a link to your page?

    Javascript operates on a single page and cannot do anything between two different pages on your site.

    You could look into using Ajax to bring in outside content, but it would be much easier to store the div in a separate file and import it into both pages.

    You might want to look into using a serverside language like PHP as well, since this sort of thing is easier to do that way. It won't operate live on the page (you'll need to click a link and reload the whole page), but that's standard.
    And you can combine Ajax and PHP if you want, later.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Quote Originally Posted by djr33 View Post
    Javascript operates on a single page and cannot do anything between two different pages on your site.
    That's not entirely true. If you do something like:
    <body onload="alert(document.referrer)">
    in file2.html, and:
    <a href="file2.html">file 2</a>
    in file1.html, then loading file2 from within file1 will produce an alert containing the URL of the latter. So we could use document.referrer for swapping divs in file2.html (only works online) by doing something like:
    if(document.referrer==url_of_file1){swap_function}.
    ===
    Arie Molendijk.
    Last edited by molendijk; 02-24-2012 at 12:01 AM. Reason: Adding an explanatory line

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    That's not what I meant. You can certainly coordinate several pages, such as by using cookies.

    But you can't import content from within one page into another page, at least not in an easy way. You can't just 'grab' it.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    If swapDIV is to be interpreted as import content from file1, then you're right. I don't know what the person means exactly by swapDIV.
    ===
    Arie.

  6. #6
    Join Date
    Feb 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Can I post my code here?
    I put a sample page together to show what it is I'm doing, and trying to do.
    Btw, while putting this page together another problem with my code reared its' head.
    So this has turned into 2 questions.
    I'm just not sure how to post code here, I don't use boards much and I don't want to just ignorantly slap it into this post.
    Code consists of HTML, CSS, & JavaScript.
    Thanks

  7. #7
    Join Date
    Feb 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Posting Test Only

    Code:
    <html>
     <script language="JavaScript" type="text/javascript">
    	function swapDiv(divID)
    {
          if(divID=='div001') {
          document.getElementById('div001').style.display="block";
          document.getElementById('div002').style.display="none";
          document.getElementById('div003').style.display="none";
          document.getElementById('div004').style.display="none";
    }
     </script>
    <style type="text/css">
    	#mcont {
                	margin:0 auto;
                	border : solid 2px #000; 
               	padding : 0px; 
                	width : 400px; 
                	height : 400px; 
                	text-align:center;
                	color: #FF0033;
            	}
    </style>
    <body>
    <body>
    <div>
    
    </div>
    </body>
    </html>

  8. #8
    Join Date
    Feb 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I've pasted the code I'm working on below.

    Code:
    <html>
      <!-- Main Page Script; Name of this Page is "main.html" -->
    
     <script language="JavaScript" type="text/javascript">
    	function swapDiv(divID)
    {
          if(divID=='div001') {
          document.getElementById('div001').style.display="block";
          document.getElementById('div002').style.display="none";
          document.getElementById('div003').style.display="none";
          document.getElementById('div004').style.display="none";
    }
          if(divID=='div002') {
          document.getElementById('div001').style.display="none";
          document.getElementById('div002').style.display="block";
          document.getElementById('div003').style.display="none";
          document.getElementById('div004').style.display="none";
    }
    	  if(divID=='div003') {
          document.getElementById('div001').style.display="none";
          document.getElementById('div002').style.display="none";
          document.getElementById('div003').style.display="block";
          document.getElementById('div004').style.display="none";
    }
          if(divID=='div004') {
          document.getElementById('div001').style.display="none";
          document.getElementById('div002').style.display="none";
          document.getElementById('div003').style.display="none";
          document.getElementById('div004').style.display="block";
    }
    }
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
     </script>
    <style type="text/css">
    	#mcont {
                	margin:0 auto;
                	border : solid 2px #000; 
               	padding : 0px; 
                	width : 400px; 
                	height : 400px; 
                	text-align:center;
                	color: #FF0033;
            	}
    	#div001 {
    	display:none 
            	width : 399px; 
           	 height : 299px; 
            	overflow-y: auto;
    	overflow-x: hidden;
            	text-align:center;
            	color: #000000;"
    	}
    	#div002 {
    	display:none; 
            	width : 399px; 
           	 height : 299px; 
            	overflow-y: auto;
    	overflow-x: hidden;
            	text-align:center;
            	color: #000000;"
    	}
    	#div003 {
    	display:none; 
            	width : 399px; 
           	 height : 299px; 
            	overflow-y: auto;
    	overflow-x: hidden;
            	text-align:center;
            	color: #000000;"
    	}
    	#div004 {
    	display:none;
            	width : 399px; 
           	 height : 299px; 
            	overflow-y: auto;
    	overflow-x: hidden;
            	text-align:center;
            	color: #000000;"
    }
    </style> 
    <body>
    <div id="mcont">
    <div  style="width:399px; height:44px; text-align:center; border : solid 1px #000; margin:0 auto; padding-top : 5px;">
    HEADER
    </div>
    <div style="width:399px; height:299px; border : solid 1px #000; margin:0 auto;">
    <div id="div001">
    <h3> Home Content</h3>
    <br/>
    <p>As you can see by clicking the links below.</p>
    <p>Just the content in this DIV changes.</p>
    <p>The 'main.html' page, this page does not.</p>
    <p>I like this..</p>
    </div>
    <div id="div002"> 
    <h3> About Content</h3>
    <br/>
    <p>The 'main.html' page doesn't change.</p>
    <p>What I can not figure out is the following.</p>
    <p>Lets say the user clicks on a 'target="_blank"' link HERE.</p>
    <p>On the new blank page are the same links as below.</p>
    </div>
    <div id="div003"> 
    <h3> Galleries Content</h3>
    <br/>
    <p>What can I do to get those links on that entirely diff. page.</p>
    <p>...To close itself while at the same time...</p>
    <p>... going to the link on this page?</p>
    <p>Closing itself won't be a prob coding.</p>
    <p>The navigating is.</p>
    </div>
    <div id="div004"> 
    <h3> Contact Me Content</h3>
    <br/>
    <p>On a completely different note.</p>
    <p> Hope you don't mind my asking a 2nd question.</p>
    <p>This div layout works in all my browsers except...</p>
    <p>IE. Any idea what I'm missing?</p>
    <p>Many thanks for any help</p>
    </div>
    <div  style="width:400px; height:50px; text-align:center; border : solid 0px #000; padding-top : 5px;">
    FOOTER MENUS<br/>
    <a href="#" onclick="swapDiv('div001')" title="Click here to Go Back Home.">Home</a> | 
    <a href="#" onclick="swapDiv('div002')" title="Click here to Learn About Me.">About Me</a> | 
    <a href="#" onclick="swapDiv('div003')" title="Click here to visit Our Photo Galleries.">Galleries</a> | 
    <a href="#" onclick="swapDiv('div004')" title="Click here to Contact Me.">Contact Me</a>
    </div>
    </div>
    </body>
    </html>
    As you can see by this layout, clicking the Footer Menus,
    changes the content in in the middle DIV.
    The 'main.html' page, does not reload.
    I like this...
    What I can not figure out is this;
    Lets say the user clicks on a 'target="_blank"' link.
    On this new blank page are the same links that are on the main.html page.
    What can I do to get those links on that new blank page,
    ...To close itself and at the same time...
    ... navigate to the clicked link on the main.html page?
    I know the code to close itself.
    Getting the navigation to work I don't know.
    The research I've done so far doesn't seem to present a solution.
    On a completely different note, I've a 2nd question. Popped up while slapping this together.
    Hope you don't mind my asking and that it is simple to answer.
    This div layout works in all my browsers except...Internet Explorer.
    Any idea what I'm missing?
    Many thanks for any help.

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
  •