By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,450 Members | 980 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,450 IT Pros & Developers. It's quick & easy.

query_string <base> JS

P: n/a
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.

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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 "<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.


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
Jul 23 '05 #2

P: n/a
Ivo
"Ivo" wrote
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[i].target=location.search.substring(1);
of course
I
}


Jul 23 '05 #3

P: n/a
Gilbert Saint-Flour wrote:
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
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.