query_string <base> JS

  • Thread starter Gilbert Saint-Flour
  • Start date
G

Gilbert Saint-Flour

Hello:

I have this one line of PHP code which I'd like to convert to Javascript.
The PHP code conditionally issues a BASE statement when the html page
is called with a frame name, e.g. href=index2.php?frame2

<html>
<head>
<? $tag = $_SERVER["QUERY_STRING"]; if(empty($tag)) {; } else { echo "<base target=$tag>"; } ?>
</head>
<body> . . . .

The problem is that I don't have PHP on my system and can't view the page,
unless I upload it to the server. I'd like to replace the php code with
javascript, but I don't know much about either php or JS. I've been
looking all over for an hour but haven't found the solution. Can one of
you get me started? Thanks.
 
I

Ivo

"Gilbert Saint-Flour" asked:
I have this one line of PHP code which I'd like to convert to Javascript.
The PHP code conditionally issues a BASE statement when the html page
is called with a frame name, e.g. href=index2.php?frame2

<html>
<head>
<? $tag = $_SERVER["QUERY_STRING"]; if(empty($tag)) {; } else { echo
</head>
<body> . . . .

The problem is that I don't have PHP on my system and can't view the page,
unless I upload it to the server. I'd like to replace the php code with
javascript, but I don't know much about either php or JS. I've been
looking all over for an hour but haven't found the solution. Can one of
you get me started? Thanks.

Replacing php with javascript? Usually the request is the other way around,
because servers may or may not run PHP, but at least you know, while
end-users may or may not have javascript, and you will never know.
A javascript that would do what the above does:

if (location.search) {
var ls = document.links;
for(var i=ls.length;i--;) ls.target=location.search.substring(1);
}

This code must not run before all links in the document have loaded, so
either onload or after the body content (but to validate it must be before
the end body tag).
HTH
Ivo
 
I

Ivo

if (location.search) {
var ls = document.links;
for(var i=ls.length;i--;) ls.target=location.search.substring(1);

That should have been
for(var i=ls.length;i--;) ls.target=location.search.substring(1);
of course
I
 
M

Mick White

Gilbert said:
Hello:

I have this one line of PHP code which I'd like to convert to Javascript.
The PHP code conditionally issues a BASE statement when the html page
is called with a frame name, e.g. href=index2.php?frame2

<html>
<head>
<? $tag = $_SERVER["QUERY_STRING"]; if(empty($tag)) {; } else { echo "<base target=$tag>"; } ?>
</head>
<body> . . . .

<head>
<script type="text/JavaScript">
if(x=location.search.toString()){
document.write("<base target="+x.substring(1)+">")
}
</script>
Mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top