1

I did something like this

<head>
<script src="trans.js" type="text/javascript"></script>
<title><script>trans("Configuration: Status - Software")</script></title>
</head>

However the web title looks like

trans("Configuration: Status - Software")

Why is the js not working here,What should modify to make it work?

Here's what tran.js look like

function trans(key)
{
  document.write(getkey(key));
}
function getkey(key)
{
   var text;
   text = lang_pack[key];

   if (text == undefined || text == "")
   {

      text = key;


   }
   return(text);
}
2
  • the <script> disappeared when I post it ? Commented Feb 25, 2014 at 5:57
  • using either JS or jquery setup the document.load function and set it from there. Commented Feb 25, 2014 at 5:59

6 Answers 6

3

I'm not sure you can use a script inside of a title tag -- can you move it into a different block?

It's unclear exactly what trans.js is, but you can try:

<script>
    document.title = trans('Configuration: Status -Software');
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

It just return another string.
@JohnnyChen Then yeah, you should be good with moving it into a different block (preferably into a different file, for unobtrusive Javascript).
1

You should try setting the title in javascript like

 document.title = trans('Configuration: Status - Software');

3 Comments

I am thinking the OP wants to set the title as the result of the function trans
@user2310289 this answer is still correct, we just don't know what's in function trans, and the answer can be easily modified by the OP. we don't have to do everything for them
New answer is completely different and is now valid.
0
var temp = document.getElementsByTagName("title").innerHTML;

 temp[0].innerHTML = "your new title";

1 Comment

You can get element by tag name "title" and change html of that element thats it..
0

Try including the src in the same script tag as the function call:

<head> <script src="trans.js" type="text/javascript">trans("Configuration: Status - Software")</script></title> </head>

Comments

0

Try this:

<head>
  <script src="trans.js" type="text/javascript"></script>
  <title></title>
  <script>document.title = getkey("Configuration: Status - Software")</script>
</head>

Comments

0

You mean this?

<head>
   <title>This is Test 1st</title>
   <script>
      var field = "This is Test 2nd";
      $("title").append(field);
   </script>
</head>

you need is a jquery library.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.