DNForum - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars
DNForum - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars
Quick Search:  
Register Now! Welcome to Dnforum.com You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us.
Go Back   DNForum - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars > Content Development > Website Development and Design Discussion > Coding/Programming/Languages
Reply
 
LinkBack Thread Tools Display Modes
Old 11-29-2007, 04:28 PM   #1 (permalink)
DNF Newbie
 
Last Online: 03-08-2008 07:47 AM
iTrader: (0)
Join Date: Sep 2004
Posts: 29
DNF$: 113


changing an image based on page title

Hi,

I want to change the source of an image depending on the page title i.e. boats.html would show boats.jpg and car.htm would show car.jgp. I'm guessing some sort of javascript would be in order, but haven't got a clue really. Could anyone suggest anything?

worked it out:

<script language="JavaScript">
<!--
function setimage()
{
var picsource = document.URL.split('/').pop().split('.').shift();
var str=picsource +'.jpg';
document.images['monthimage'].src=str;
}
</script>

Last edited by fini; 11-29-2007 at 04:33 PM. Reason: Automerged Doublepost
fini is offline   Reply With Quote
Old 01-01-2008, 07:36 AM   #2 (permalink)
Platinum Lifetime Member
 
Last Online: 05-12-2008 05:14 PM
iTrader: (2)
Join Date: Dec 2007
Posts: 153
DNF$: 830
Location: UK
Country:


you could also try using document.title instead of all that split/pop/shift stuff:

var picsource = document.title;

EDIT: it might be "window.title" actually, not sure. one of those two.
sunja is offline   Reply With Quote
Old 04-22-2008, 06:26 AM   #3 (permalink)
Platinum Lifetime Member
 
xrvel's Avatar
 
Name: Kurniawan
Last Online: 05-05-2008 06:34 AM
iTrader: (0)
Join Date: Nov 2007
Posts: 10
DNF$: 330
Location: Indonesia
Country:


Quote:
Originally Posted by sunja View Post
you could also try using document.title instead of all that split/pop/shift stuff:

var picsource = document.title;

EDIT: it might be "window.title" actually, not sure. one of those two.
The document.title is the correct one.

If a document have no title, the document URL is displayed in title section, but, the JavaScript still considers the title as empty, therefore, we must check it based from the document URL. Here's the full code.
PHP Code:
<script type="text/javascript">
function 
setImage(imageId) {
    var 
docTitle document.title '';
    var 
docUrl document.location '';
    var 
picSource '';

    
picSource docUrl.split('/').pop().split('.').shift();
    
picSource picSource +'.jpg';
    
alert('Pic Source = ' picSource);
    if (
document.getElementById(imageId)) {
        
document.getElementById(imageId).src picSource;
    } else {
        
alert('Image not found');
    }
}
</script>

<img src="a.jpg" id="your-image-id" />
<input type="button" value="Change Image" onclick="setImage('your-image-id')" /> 

Last edited by xrvel; 04-22-2008 at 06:44 AM. Reason: Automerged Doublepost
xrvel is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -4. The time now is 01:21 AM.
Copyright @2001-2008 DNForum.com