www.webdeveloper.com
Results 1 to 11 of 11

Thread: Reverse Order Of Title Tag

  1. #1
    Join Date
    Jul 2009
    Posts
    15

    Reverse Order Of Title Tag

    Hi Guys

    Is there a way that JavaScript can be used to reverse the order of a title tag?

    Let me explain:

    My title currently gets created dynamically by calling the breadcrumb path depending on which page I'm on. The title looks like:
    PHP Code:
    <title><?php echo $page_title?></title>
    When I'm 3 levels deep, the title would look something like:
    Accommodation | Guest Houses | My Guest House

    I need the title to be reversed, so that on the same page it would show:
    My Guest House | Guest Houses | Accommodation

    Is this possible with JS?

  2. #2
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    		<title>Fee | Fie | Foe | Fum</title>
    		<script type="text/javascript">
    		onload = function () {document.title = document.title.split (/\s*\|\s*/).reverse().join (' | ')}
    		</script>
    	</head>
    	<body>
    	
    	</body>
    </html>
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  3. #3
    Join Date
    Jul 2009
    Posts
    15
    Thanx for that, but still not working.

  4. #4
    Join Date
    Jul 2009
    Posts
    15
    This is what the source code looks like:
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html dir="ltr">
    <
    head>
              <
    meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
              <
    titleAccommodation Guest Houses Ekala Guest Farm and Eco Tours Johannesburg  </title>
              <
    script type="text/javascript">
          
    onload = function () {document.title document.title.split (/\s*\|\s*/).reverse().join (' | ')}
          
    </script> 

  5. #5
    Join Date
    May 2003
    Location
    Between Baltimore and DC
    Posts
    3,579
    Your code is missing \ in 2 places. Look at the example again.

    Eric

  6. #6
    Join Date
    Jul 2009
    Posts
    15
    This is how I inserted the code:
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html dir="ltr">
    <
    head>
              <
    meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
              <
    titleAccommodation Guest Houses Ekala Guest Farm and Eco Tours Johannesburg  </title>
              <
    script type="text/javascript">
          
    onload = function () {document.title document.title.split (/\s*\|\s*/).reverse().join (' | ')}
          
    </script> 
    This is what shows in "View >> Page Source":
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    html dir="ltr">
    <
    head>
              <
    meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
              <
    titleAccommodation Guest Houses Ekala Guest Farm and Eco Tours Johannesburg  </title>
              <
    script type="text/javascript">
          
    onload = function () {document.title document.title.split (/s*|s*/).reverse().join (' | ')}
          
    </script> 

  7. #7
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    That script is not what I posted.
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  8. #8
    Join Date
    Jul 2009
    Posts
    15
    Hi Charles

    This is the script you posted:
    PHP Code:
    <script type="text/javascript">
            
    onload = function () {document.title document.title.split (/\s*\|\s*/).reverse().join (' | ')}
            
    </script> 
    Did you mean the entire code with html, head, body, etc.?

  9. #9
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    Nope, as A1ien51 noted above that's not what I posted.
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  10. #10
    Join Date
    Jul 2009
    Posts
    15
    My apologies. I wrapped php tags around the code, so it stripped out the \. Anyway, I used the code as you posted, but still no luck. Any ideas?

    Thanx again for the help.

  11. #11
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    Quote Originally Posted by AlvinSA View Post
    Any ideas?
    You are then doing something else wrong. The example I posted was tested and found to work. Can you post something that doesn't work?
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles