Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set page title to a variable I can use

Status
Not open for further replies.

Pirellio

Programmer
Aug 25, 2008
18
US
I need to Set page title to a variable I can use in a meta tag.

I get this to work - and title shows in the input field

<SCRIPT LANGUAGE = JavaScript>
//alert(document.title)
function getTitle()
{document.titleForm.theTitle.value = document.title};
</SCRIPT>

<body onload="getTitle();">
<form name="titleForm">
<input type="text" name="theTitle">
</form>

But now I need something here.

<meta tag name="Funnel" content="theTitle">

Any suggestions?

 
Hi

You mean to get the value of the [tt]meta[/tt] tag's [tt]content[/tt] attribute where the [tt]name[/tt] attribute's value is "Funnel" ?
Code:
alert(document.evaluate('//meta[@name="Funnel"]',document,null,XPathResult.ANY_UNORDERED_NODE_TYPE,null).singleNodeValue.getAttribute('content'))
Note that adding some error checking would be nice...

Feherke.
 
No
I am trying to make the Meta tag dynamic from page to page

So with every new page - the meta tag will change to that page title.

<title>Home Page</title>

Grab the title an set the meta tag the same content.
<meta tag name="funnel" content="Home Page">

Then they go to contact us page

<title>Contact Us</title>

<meta tag name="funnel" content="Contact Us">

Does that make sense?

I am using webtrends to track funnel meta tag

 
Does that make sense?

Yes - perfectly. So I'll ask again - why do you need to use JavaScript to do this?

If you're on the "Home" page and your markup contains this:

Code:
<title>Home</title>

Why not simply add this line below it:

Code:
<meta tag name="funnel" content="Home">

And if you're on the "Contact us" page and your markup contains this:

Code:
<title>Contact Us</title>

Why not simply add this line below it:

Code:
<meta tag name="funnel" content="Contact Us">

I just don't get why you cannot output the meta tag at the same time you output the title tag. What are you not telling us?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
the title is dynamically driven, and there are to many different pages where it is set up differently, so I need to use the title to populate the meta tag.

I am trying to get to work below.

<SCRIPT LANGUAGE = JavaScript>
//alert(document.title)
{
document.write("<META NAME=\"funnel\" CONTENT=\"" + document.title + "\">\n");


var meta = document.createElement('meta');
meta.setAttribute('name', 'funnel1');
meta.setAttribute('content', document.title);
document.getElementsByTagName('head')[0].appendChild(meta); }
</SCRIPT>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top