Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1
    Join Date
    Oct 2006
    Location
    Merseyside
    Posts
    2,335
    Tokens
    0

    Latest Awards:

    Default Javascript Help please :)

    Hi,

    I took the advice of other people in another thread and use javascript for a navigation. I have a small problem. I need to know how to set a default page like you do with iframes.

    The javascript code is:
    Code:
    function showhide(id){
    if (document.getElementById){
    obj = document.getElementById(id);
    if (obj.style.display == "none"){
    obj.style.display = "";
    } else {
    obj.style.display = "none";
    }
    }
    }
    var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
    var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only
    
    if (document.getElementById){ //DynamicDrive.com change
    document.write('<style type="text/css">\n')
    document.write('.submenu{display: none;}\n')
    document.write('</style>\n')
    }
    
    function SwitchMenu(obj){
        if(document.getElementById){
        var el = document.getElementById(obj);
        var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
            if(el.style.display != "block"){ //DynamicDrive.com change
                for (var i=0; i<ar.length; i++){
                    if (ar[i].className=="submenu") //DynamicDrive.com change
                    ar[i].style.display = "none";
                }
                el.style.display = "block";
            }else{
                el.style.display = "none";
            }
        }
    }
    
    
    function get_cookie(Name) { 
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { 
    offset += search.length
    end = document.cookie.indexOf(";", offset);
    if (end == -1) end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
    }
    
    function onloadfunction(){
    if (persistmenu=="yes"){
    var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
    var cookievalue=get_cookie(cookiename)
    if (cookievalue!="")
    document.getElementById(cookievalue).style.display="block"
    }
    }
    
    function savemenustate(){
    var inc=1, blockid=""
    while (document.getElementById("sub"+inc)){
    if (document.getElementById("sub"+inc).style.display=="block"){
    blockid="sub"+inc
    break
    }
    inc++
    }
    var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
    var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
    document.cookie=cookiename+"="+cookievalue
    }
    
    if (window.addEventListener)
    window.addEventListener("load", onloadfunction, false)
    else if (window.attachEvent)
    window.attachEvent("onload", onloadfunction)
    else if (document.getElementById)
    window.onload=onloadfunction
    
    if (persistmenu=="yes" && document.getElementById)
    window.onunload=savemenustate
    
    function MM_jumpMenu(targ,selObj,restore){ //v3.0
      eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
      if (restore) selObj.selectedIndex=0;
    }
    
    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_jumpMenuGo(selName,targ,restore){ //v3.0
      var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
    }
    
    var bustcachevar=1 
    var loadedobjects=""
    var rootdomain="http://"+window.location.hostname
    var bustcacheparameter=""
    
    function dopage(url, containerid){
        document.getElementById("content_main").innerHTML = '<div align="center"><img src="images/habboimages/CNY_KungFu_dude.gif" border="0" /><br><font size="1" color="white" face="verdana"><b>Finding</b> and <b>loading</b> page...</font></div>';
    var page_request = false
    if (window.XMLHttpRequest) 
    page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){ 
    try {
    page_request = new ActiveXObject("Msxml2.XMLHTTP")
    } 
    catch (e){
    try{
    page_request = new ActiveXObject("Microsoft.XMLHTTP")
    }
    catch (e){}
    }
    }
    else
    return false
    page_request.onreadystatechange=function(){
    loadpage(page_request, containerid)
    }
    if (bustcachevar) 
    bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
    page_request.open('GET', url+bustcacheparameter, true)
    page_request.send(null)
    }
    
    function loadpage(page_request, containerid){
        document.getElementById("content_main").innerHTML = '<div align="center"><img src="images/habboimages/CNY_KungFu_dude.gif" border="0" /><br><font size="1" color="white" face="verdana"><b>Finding</b> and <b>loading</b> page...</font></div>';
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
    document.getElementById(containerid).innerHTML=page_request.responseText
    }
    
    function loadobjs(){
    if (!document.getElementById)
    return
    for (i=0; i<arguments.length; i++){
    var file=arguments[i]
    var fileref=""
    if (loadedobjects.indexOf(file)==-1){ 
    if (file.indexOf(".js")!=-1){ 
    fileref=document.createElement('script')
    fileref.setAttribute("type","text/javascript");
    fileref.setAttribute("src", file);
    }
    else if (file.indexOf(".css")!=-1){ 
    fileref=document.createElement("link")
    fileref.setAttribute("rel", "stylesheet");
    fileref.setAttribute("type", "text/css");
    fileref.setAttribute("href", file);
    }
    }
    if (fileref!=""){
    document.getElementsByTagName("head").item(0).appendChild(fileref)
    loadedobjects+=file+" " 
    }
    }
    }
    
    function doupdate(update)
    {
    var title = document.getElementById('title');
    title.innerHTML = update;
    }
    If I cannot do it that way how else would I do it or is there away of setting the <div> to do it.

    Thanks for anyone who can help.

  2. #2
    Join Date
    Feb 2006
    Location
    Ontario Canada
    Posts
    4,587
    Tokens
    0

    Latest Awards:

    Default

    change center to the div name and change /home.php to your homepage
    <body onLoad="LoadPage('/home.php','center');">

    .:.:#14:.:. .:.: Impossible Is Nothing :.:. .:.: 845 Rep:.:.
    .:.: Stand up for what is right, even if you stand alone:.:.


  3. #3
    Join Date
    Oct 2006
    Location
    Merseyside
    Posts
    2,335
    Tokens
    0

    Latest Awards:

    Default

    That does not work

  4. #4
    Join Date
    Feb 2006
    Location
    Ontario Canada
    Posts
    4,587
    Tokens
    0

    Latest Awards:

    Default

    link to script on dymanic drive?

    .:.:#14:.:. .:.: Impossible Is Nothing :.:. .:.: 845 Rep:.:.
    .:.: Stand up for what is right, even if you stand alone:.:.


  5. #5
    Join Date
    Oct 2006
    Location
    Merseyside
    Posts
    2,335
    Tokens
    0

    Latest Awards:

    Default

    Im not sure of it I was sent this by a friend ill try looking around Dynamic Drive now.

  6. #6
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:


  7. #7
    Join Date
    Oct 2006
    Location
    Merseyside
    Posts
    2,335
    Tokens
    0

    Latest Awards:

    Thumbs down

    Nope =[

    The page is loading when I click a link but isn't automatically loading when I load the page.

    Ill tell you what I done:

    Code:
    <script>
    //Set up variables
    var xmlhttp ;
    var thediv;
    function LoadPage(page,usediv) {
             // Set up request varible
             try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");}  catch (e) { alert("Error: Could not load page.");}
             //Show page is loading
             document.getElementById(usediv).innerHTML = 'Loading Page...';
             //scroll to top
             scroll(0,0);
             //Store div in use
             thediv = usediv;
             //send data
             xmlhttp.onreadystatechange = ShowPage;
             xmlhttp.open("GET", page);
             xmlhttp.send(null);
             //Stop any link loading normaly
             return false;
    }
    function ShowPage(){
             //Check page is completed and there were no problems.
             if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
                    //Write data returned to page
                    document.getElementById(thediv).innerHTML = xmlhttp.responseText;
             }
    }
    </script>
    Ive put that in the head section of the code.

    Code:
    <a href="home.php" onclick="return LoadPage('home.php','content_main');">
    I have placed that where my content would be.

    I think I am doing it correctly anyway.

  8. #8
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    did you make a div?

    <div id="content_main"></div>

  9. #9
    Join Date
    Oct 2006
    Location
    Merseyside
    Posts
    2,335
    Tokens
    0

    Latest Awards:

    Default

    Yes, It still shows the template and the content bit is blank.

  10. #10
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    Link me to the page and i will let firebug check it out

Page 1 of 2 12 LastLast

Posting Permissions

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