Results 1 to 5 of 5

Thread: Need help with image display on page

  1. #1
    Join Date
    Nov 2009
    Location
    Westland - The Hague
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Need help with image display on page

    Dear all,
    I was wondering if someone could hep me with the following script. I've set up this script by myself, but I don't know what I do wrong. I do not know so much about JavaScript.

    What I want is the following: I am planning to combine two domains to one, but, what I want is that users calling www.rick.travel, will see the Rick.Travel logo and users which are calling www.worldofrick.nl, will see the World of Rick logo.

    So, as far, I have the following code, but it doesn't work:
    Code:
    function showLogo()
    {
    if (domain=="rick.travel")
    document.write('<a href="http://www.rick.travel"><img src="http://www.rick.travel/data/images/rick.png" alt="Rick.Travel" border="0" /></a>');
    else 
    document.write('<a href="http://www.worldofrick.nl"><img src="http://data.worldofrick.nl/world/titel.png" alt="World of Rick" border="0" /></a>');
    }

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well since I'm almost positive you have a PHP enabled server and that the filename of the page is index.php (took just a little snooping to determine that is likely the case), you could and probably should use PHP for this. That is if there will still be two domain names as shown in the browser's address bar. Will there be?

    But I'm not real up on PHP, so I'd ask in the PHP section. You would probably want to test the $SERVER_NAME variable and pick the href for the link and the src and alt for the image on the basis of that. Something like:

    PHP Code:
    <?php
    if($SERVER_NAME == www.rick.travel || $SERVER_NAME == rick.travel)
    echo 
    '<a href="http://www.rick.travel"><img src="http://www.rick.travel/data/images/rick.png" alt="Rick.Travel" border="0" /></a>';
    else
    echo 
    '<a href="http://www.worldofrick.nl"><img src="http://data.worldofrick.nl/world/titel.png" alt="World of Rick" border="0" /></a>';
    ?>
    This would go in place of:

    HTML Code:
    <a href="http://www.rick.travel"><img src="http://data.worldofrick.nl/images/ricktravel.png" alt="Rick.Travel" class="print" border="0" width="396" height="90" /></a>
    and the one for the other logo on the other page.

    IMPORTANT NOTE: The above is just pseudo PHP code. It may work, but if it doesn't, folks in the PHP section can correct it for you.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    rick.travel (11-26-2009)

  4. #3
    Join Date
    Nov 2009
    Location
    Westland - The Hague
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanks!!! It worked for me!!! My PHP code is now the following (it's correct that rick.travel is an alias on the domain worldofrick.nl):


    PHP Code:
    if (preg_match("/rick.travel/i"$_SERVER['HTTP_HOST'])) {
        echo 
    "<a href=\"http://www.rick.travel\"><img src=\"http://data.worldofrick.nl/images/ricktravel.png\" alt=\"Rick.Travel\" class=\"print\" border=\"0\" width=\"396\" height=\"90\" /></a>";
    } else {
        echo 
    "<a href=\"http://www.worldofrick.nl\"><img src=\"http://data.worldofrick.nl/world/titel.png\" alt=\"World of Rick\" class=\"print\" border=\"0\" width=\"396\" height=\"90\" /></a>";


  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Great! It is my understanding that a preferred method of doing the same thing would be (if it works):

    PHP Code:
    <?php
    if (preg_match("/rick.travel/i"$_SERVER['HTTP_HOST'])) { 
    ?>
    <a href="http://www.rick.travel"><img src="http://data.worldofrick.nl/images/ricktravel.png" alt="Rick.Travel" class="print" border="0" width="396" height="90" /></a>
    <?php
    } else { 
    ?>
    <a href="http://www.worldofrick.nl"><img src="http://data.worldofrick.nl/world/titel.png" alt="World of Rick" class="print" border="0" width="396" height="90" /></a>
    <?php
    }
    ?>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #5
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I don't know that it's "preferred", exactly, but it can be easier. I generally only exit the php tags when I have a large, static block of html. For just a few lines, I prefer to use single quotes (especially for html tags, where attributes require multiple double-quotes that would otherwise need to be escaped, as above).
    PHP Code:
    <?php
    if (preg_match("/rick.travel/i"$_SERVER['HTTP_HOST'])) { 
        echo 
    '<a href="http://www.rick.travel"><img src="http://data.worldofrick.nl/images/ricktravel.png" alt="Rick.Travel" class="print" border="0" width="396" height="90" /></a>';
    } else { 
        echo 
    '<a href="http://www.worldofrick.nl"><img src="http://data.worldofrick.nl/world/titel.png" alt="World of Rick" class="print" border="0" width="396" height="90" /></a>';
    }
    ?>

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
  •