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
    216
    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,081
    Thanks
    23
    Thanked 592 Times in 591 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
    1,911
    Thanks
    15
    Thanked 227 Times in 227 Posts
    The javascript inside your Printmypage function has to read:

    document.title = title1;

  • #4
    Regular Coder
    Join Date
    May 2006
    Posts
    216
    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
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 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
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 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
    •