473,395 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

query_string <base> JS

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
3 1603
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Weston C | last post by:
I'm trying to get the href attribute from the base tag in the document head. The following does not seem to work... any ideas what I'm doing wrong? if(!(document.getElementsByTagName) ||...
2
by: CD | last post by:
Is this possible: class base; class derived; //:public base vector <base*> bList; vector<derived*> dList; //add some derived class pointer entries to dList;
2
by: Siemel Naran | last post by:
This code fails compile std::auto_ptr<Base> f() { std::auto_ptr<Derived> out(new Derived()); return out; } There is ambiguity between a templated constructor and templated operator...
1
by: Chris Sharman | last post by:
I'm seeing quite a few 404 errors, all from an agent/browser which calls itself "Mozilla/4.0 (compatible; BorderManager 3.0)". They appear to be from a built page like...
3
by: SJ | last post by:
Hi, I have a problem with the HTML <base> element, URL re-writing and Postback. We are using URL re-writing on the server, and I'd like to use the base element to make the URLs in the ASPX pages...
0
by: emma_middlebrook | last post by:
Hi Hopefully the title is quite accurate but here's some more information. I have a load of ICollection<references hanging off a class e.g. ICollection<X>, ICollection<Yetc etc. Each of the...
3
by: yan | last post by:
Hello everybody, I am new so this is the occasion to say hello to everybody. I have a problem with absolute/relative paths. I have to create a static documentation in html for a project and I have...
16
by: call_me_anything | last post by:
why is the following not allowed : vector <Base *vec_of_base; vector <Derived *vec_of_derived; vec_of_base = vec_of_derived; Note : The following is allowed :
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.