Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    May 2006
    Posts
    227
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Variable value with page Title?

    I have Title like:
    Title1 | Title2 | Title2 | Mydomain

    Javascript code like:
    PHP Code:

    <a href="#" class="button1" style="width:200px;" onclick="Printmypage('printmypage','title1','popup',true)"><class="icon"></i>Print page</a></div><div id="printmypage"
    how to change automatic this variable title1
    ('printmypage','title1','popup',true)

    into existing page Title with support of Javascript and/or PHP?

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,696
    Thanks
    25
    Thanked 658 Times in 657 Posts
    Really not completely sure what you want. Maybe this is it for both things I think you want:

    Code:
    <?php
    $title = 'title1';  // Or anything you want here
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Big Title</title>
    <script type="text/javascript">
    function Printmypage(a,b,c,d)
    {
    	document.title = b;
    }
    </script>
    </head>
    <body>
    <a href="#" class="button1" style="width:200px;" onclick="Printmypage('printmypage','<?php echo $title; ?>','popup',true)">
    <i class="icon"></i>Print page
    </a>
    <div id="printmypage"></div>
    </body>
    </html>

  • #3
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,451
    Thanks
    17
    Thanked 275 Times in 275 Posts
    The javascript inside your Printmypage function has to read:

    document.title = title1;

  • #4
    Regular Coder
    Join Date
    May 2006
    Posts
    227
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DrDOS View Post
    The javascript inside your Printmypage function has to read:

    document.title = title1;
    How to put PHP inside this title1 to read from javascript as this language is client side.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,635 Times in 4,597 Posts
    Code:
    document.title = "<?php echo somePHPvariableOrExpression; ?>";
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,635 Times in 4,597 Posts
    But if you are doing this from PHP, why not just do it *IN* the title?
    Code:
    <head>
    <title><?php echo whateverPHPstuffYouWant; ?></title>
    ...
    </head>
    ???
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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