query_string <base> JS

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gilbert Saint-Flour

    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_STRI NG"]; 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.

  • Ivo

    #2
    Re: query_string &lt;base&gt; JS

    "Gilbert Saint-Flour" asked:[color=blue]
    > 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_STRI NG"]; if(empty($tag)) {; } else { echo[/color]
    "<base target=$tag>"; } ?>[color=blue]
    > </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.
    >[/color]

    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.searc h) {
    var ls = document.links;
    for(var i=ls.length;i--;) ls.target=locat ion.search.subs tring(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


    Comment

    • Ivo

      #3
      Re: query_string &lt;base&gt; JS

      "Ivo" wrote[color=blue]
      > if (location.searc h) {
      > var ls = document.links;
      > for(var i=ls.length;i--;) ls.target=locat ion.search.subs tring(1);[/color]

      That should have been
      for(var i=ls.length;i--;) ls[i].target=locatio n.search.substr ing(1);
      of course
      I
      [color=blue]
      > }[/color]



      Comment

      • Mick White

        #4
        Re: query_string &lt;base&gt; JS

        Gilbert Saint-Flour wrote:[color=blue]
        > 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_STRI NG"]; if(empty($tag)) {; } else { echo "<base target=$tag>"; } ?>
        > </head>
        > <body> . . . .[/color]

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

        Comment

        Working...