Redirect Q

Discussion in 'Computer Information' started by Paul, Mar 23, 2014.

  1. Paul

    Paul Guest

    Robert Baer wrote:
    > The following stupid snippet works:
    > <body>
    > <script>
    > if (true)
    > { location.replace('PCbase.html'); }
    > endif
    > </script>
    > </body>
    >
    > But what i want is:
    > <head>
    > <script>
    > if (true)
    > { location.replace('PCbase.html'); }
    > endif
    > </script>
    > </head>
    >
    > What code IN HEAD section will replace/"jump"?
    >


    You should really be in a web authoring or HTML
    programming group for this, to tap into experts.
    There aren't going to be enough of those programmers
    here, to answer all questions.

    The way I look at it, the <body></body>
    and <head></head> are two separate portions
    of the web page, with different purposes. You
    would not expect all the same capabilities to
    exist in both. Do you know for a fact, that
    head and body support all the same programming
    constructs ? I don't know the answer to that.

    The definition of the location.replace is here...

    http://www.w3schools.com/jsref/met_loc_replace.asp

    and there are a few examples of HTML usage here.

    http://www.w3schools.com/html/html_examples.asp

    On that last page, look at the three examples for
    some idea of what goes in the <head> section.
    It doesn't look like a lot of "programming" goes
    in there.

    HTML head Elements
    ------------------

    Specify a title for a document
    One default URL and target for all links on a page
    Provide metadata for a document

    HTH,
    Paul
     
    Paul, Mar 23, 2014
    #1
    1. Advertising

  2. Paul

    Robert Baer Guest

    The following stupid snippet works:
    <body>
    <script>
    if (true)
    { location.replace('PCbase.html'); }
    endif
    </script>
    </body>

    But what i want is:
    <head>
    <script>
    if (true)
    { location.replace('PCbase.html'); }
    endif
    </script>
    </head>

    What code IN HEAD section will replace/"jump"?
     
    Robert Baer, Mar 23, 2014
    #2
    1. Advertising

  3. Paul

    Robert Baer Guest

    Paul wrote:
    > Robert Baer wrote:
    >> The following stupid snippet works:
    >> <body>
    >> <script>
    >> if (true)
    >> { location.replace('PCbase.html'); }
    >> endif
    >> </script>
    >> </body>
    >>
    >> But what i want is:
    >> <head>
    >> <script>
    >> if (true)
    >> { location.replace('PCbase.html'); }
    >> endif
    >> </script>
    >> </head>
    >>
    >> What code IN HEAD section will replace/"jump"?
    >>

    >
    > You should really be in a web authoring or HTML
    > programming group for this, to tap into experts.
    > There aren't going to be enough of those programmers
    > here, to answer all questions.
    >
    > The way I look at it, the <body></body>
    > and <head></head> are two separate portions
    > of the web page, with different purposes. You
    > would not expect all the same capabilities to
    > exist in both. Do you know for a fact, that
    > head and body support all the same programming
    > constructs ? I don't know the answer to that.
    >
    > The definition of the location.replace is here...
    >
    > http://www.w3schools.com/jsref/met_loc_replace.asp
    >
    > and there are a few examples of HTML usage here.
    >
    > http://www.w3schools.com/html/html_examples.asp
    >
    > On that last page, look at the three examples for
    > some idea of what goes in the <head> section.
    > It doesn't look like a lot of "programming" goes
    > in there.
    >
    > HTML head Elements
    > ------------------
    >
    > Specify a title for a document
    > One default URL and target for all links on a page
    > Provide metadata for a document
    >
    > HTH,
    > Paul

    OK: will hunt for one.
    Found a way to "do it all" in the body, as follows:

    <script>
    // discover if browser is crappy Opera or crappy Safari
    str=navigator.userAgent; // Agent is unique for our purposes
    var sf=str.indexOf("Safari"); // found if browser is Chrome or Safari
    var ch=str.indexOf("Chrome"); // not found if browser is Safari
    var op=str.indexOf("Opera"); // unique for Opera
    var opt=1; // alternate shown below but not used
    ovar=window.opera; // is undefined if browser is not Opera
    if (!ovar) { opt=-1; } // unique for Opera
    // Safari gives sf=91,ch=-1; Opera gives sf=-1,op=7; Chrome gives
    sf=-1,ch>0.
    // Jump to different markup if crappy browser
    if (sf>0 && ch<0 || op>=0) { window.location.replace('Mobile.html'); }
    // ** NOTE treat crap as if mobile phone **
    // Code is a one-pager; there are mobile phones that struggle and die with
    // message "Page too large" "open media site"

    var isIE=str.indexOf("IE"); // not found in other browsers
    if (isIE>0) { window.location.replace('PCbase.html'); }
    var isMozilla=str.indexOf("Mozilla"); // Presumes in all variants;
    includes Netscape
    if (isMozilla>=0) { window.location.replace('PCbase.html'); }
    if (ch>=0) { window.location.replace('PCbase.html'); } // for Chrome

    document.write(str+"<BR>");
    document.write("At this point, browser is not Safari, Chrome, Opera or
    IE or Mozilla"+"<BR>");
    // So, ASSuME we have mobile phone browser
    // window.location.replace('Mobile.html');
    // -----^ always executes; previous valid .replace somehow bypassed
    </script>

    Above works fine, except as noted.
    NOT TESTED on a mobile phone (yet).
     
    Robert Baer, Mar 24, 2014
    #3
  4. Paul

    Paul Guest

    Robert Baer wrote:
    > Paul wrote:
    >> Robert Baer wrote:
    >>> The following stupid snippet works:
    >>> <body>
    >>> <script>
    >>> if (true)
    >>> { location.replace('PCbase.html'); }
    >>> endif
    >>> </script>
    >>> </body>
    >>>
    >>> But what i want is:
    >>> <head>
    >>> <script>
    >>> if (true)
    >>> { location.replace('PCbase.html'); }
    >>> endif
    >>> </script>
    >>> </head>
    >>>
    >>> What code IN HEAD section will replace/"jump"?
    >>>

    >>
    >> You should really be in a web authoring or HTML
    >> programming group for this, to tap into experts.
    >> There aren't going to be enough of those programmers
    >> here, to answer all questions.
    >>
    >> The way I look at it, the <body></body>
    >> and <head></head> are two separate portions
    >> of the web page, with different purposes. You
    >> would not expect all the same capabilities to
    >> exist in both. Do you know for a fact, that
    >> head and body support all the same programming
    >> constructs ? I don't know the answer to that.
    >>
    >> The definition of the location.replace is here...
    >>
    >> http://www.w3schools.com/jsref/met_loc_replace.asp
    >>
    >> and there are a few examples of HTML usage here.
    >>
    >> http://www.w3schools.com/html/html_examples.asp
    >>
    >> On that last page, look at the three examples for
    >> some idea of what goes in the <head> section.
    >> It doesn't look like a lot of "programming" goes
    >> in there.
    >>
    >> HTML head Elements
    >> ------------------
    >>
    >> Specify a title for a document
    >> One default URL and target for all links on a page
    >> Provide metadata for a document
    >>
    >> HTH,
    >> Paul

    > OK: will hunt for one.
    > Found a way to "do it all" in the body, as follows:
    >
    > <script>
    > // discover if browser is crappy Opera or crappy Safari
    > str=navigator.userAgent; // Agent is unique for our purposes
    > var sf=str.indexOf("Safari"); // found if browser is Chrome or Safari
    > var ch=str.indexOf("Chrome"); // not found if browser is Safari
    > var op=str.indexOf("Opera"); // unique for Opera
    > var opt=1; // alternate shown below but not used
    > ovar=window.opera; // is undefined if browser is not Opera
    > if (!ovar) { opt=-1; } // unique for Opera
    > // Safari gives sf=91,ch=-1; Opera gives sf=-1,op=7; Chrome gives
    > sf=-1,ch>0.
    > // Jump to different markup if crappy browser
    > if (sf>0 && ch<0 || op>=0) { window.location.replace('Mobile.html'); }
    > // ** NOTE treat crap as if mobile phone **
    > // Code is a one-pager; there are mobile phones that struggle and die with
    > // message "Page too large" "open media site"
    >
    > var isIE=str.indexOf("IE"); // not found in other browsers
    > if (isIE>0) { window.location.replace('PCbase.html'); }
    > var isMozilla=str.indexOf("Mozilla"); // Presumes in all variants;
    > includes Netscape
    > if (isMozilla>=0) { window.location.replace('PCbase.html'); }
    > if (ch>=0) { window.location.replace('PCbase.html'); } // for Chrome
    >
    > document.write(str+"<BR>");
    > document.write("At this point, browser is not Safari, Chrome, Opera or
    > IE or Mozilla"+"<BR>");
    > // So, ASSuME we have mobile phone browser
    > // window.location.replace('Mobile.html');
    > // -----^ always executes; previous valid .replace somehow bypassed
    > </script>
    >
    > Above works fine, except as noted.
    > NOT TESTED on a mobile phone (yet).


    But, are all the browsers honest ?

    http://www.nczonline.net/blog/2013/07/02/internet-explorer-11-dont-call-me-ie/

    *******

    Make sure you're getting the best from your search engine. Since every web
    developer will have done this stuff at one time or another, there will be
    some "best practices" thoughts out there.

    https://developer.mozilla.org/en-US/docs/Browser_Detection_and_Cross_Browser_Support

    http://stackoverflow.com/questions/1005153/auto-detect-mobile-browser-via-user-agent

    http://detectmobilebrowsers.com/

    There's client or server sniffing, object or useragent determination.
    More than one way to get there.

    HTH,
    Paul
     
    Paul, Mar 24, 2014
    #4
  5. Paul

    Robert Baer Guest

    VanguardLH wrote:
    > Robert Baer wrote:
    >
    >> The following stupid snippet works:
    >> <body>
    >> <script>
    >> if (true)
    >> { location.replace('PCbase.html'); }
    >> endif
    >> </script>
    >> </body>
    >>
    >> But what i want is:
    >> <head>
    >> <script>
    >> if (true)
    >> { location.replace('PCbase.html'); }
    >> endif
    >> </script>
    >> </head>
    >>
    >> What code IN HEAD section will replace/"jump"?

    >
    > My understanding of head scripts is they are executed early and BEFORE
    > displaying the document (in a window). For scripts in the HEAD, you
    > don't yet have a window to replace. Remember that the full function is
    > not 'location.replace' but "window.location.replace'. The 'location'
    > object is part of the 'window object'. The location object is accessed
    > through the [window.]location property. Similarly, you'll see use of
    > 'document.<func>' when, in fact, the document object is part of the
    > window object. The document is accessed as 'window.document' but the
    > shortform of 'document' is often used.
    >
    > 'location.replace("url") is the same as window.location.replace("url")'.
    > If head scripts execute before the displaying the document in a window
    > then you don't yet have a window to replace with a new document. Since
    > you are trying to set the URL for the document before even displaying, I
    > don't see the point of replacing a document you haven't painted yet.
    > For whatever reason you're trying this, and this is just a guess due on
    > the timing of running scripts in the HEAD, maybe you need to use
    > location.pathname instead.
    >
    > I have to wonder if this might be considered a security issue. One page
    > or hyperlink points to one page and yet you are trying to shove in a
    > different page than originally specified. You could use meta-refresh if
    > you're attempting to use interstitial pages. Most web browsers are
    > configured to allow meta-refresh. The user cannot disable meta-refresh
    > in Google Chrome (a lacking security setting) while Firefox and Internet
    > Explorer let users decide if they will permit interstital pages. Some
    > web browsers or via add-ons can intercept meta-refresh to ask the user
    > if they will allow the attempted redirection (alas, Firefox, for
    > example, won't tell the user where goes the redirection). IE just
    > disables the redirection with no clue to the user where it points (there
    > was the old IE7Pro add-on but it was long abandoned). In case your
    > visitor has meta-refresh disabled, the interstitial page should have a
    > "continue" button or hyperlink telling them click on it to move to the
    > next page.
    >
    > Note that you could define a Javascript function in the HEAD element but
    > call it inside the BODY element. The effect is to preload the HEAD
    > scripts before displaying the document. See an example at
    > http://www.dotnetheaven.com/article/how-to-use-javascript-location-replace.
    > While they're showing it used when pressing a button, maybe you could
    > use it with the onload event. You don't describe what you're trying to
    > do with the replace function.
    >
    > I just dabble in HTML to the extent of experimenting to figure out how
    > to get it to work how I want. I am not an HTML guru. The newsgroups
    > more focused on HTML and where you should ask are over at:
    >
    > alt.discuss.html
    > alt.html

    Thanks; i had read somewhere that 'location.replace' was preferred.
    Will change them back.

    Me two:).
    I just dabble in HTML to the extent of experimenting to figure out
    how to get it to work how I want. I am not an HTML guru.
    I finally figured out how to what i want with all code in the body.
     
    Robert Baer, Mar 24, 2014
    #5
  6. Paul

    Robert Baer Guest

    Paul wrote:
    > Robert Baer wrote:
    >> Paul wrote:
    >>> Robert Baer wrote:
    >>>> The following stupid snippet works:
    >>>> <body>
    >>>> <script>
    >>>> if (true)
    >>>> { location.replace('PCbase.html'); }
    >>>> endif
    >>>> </script>
    >>>> </body>
    >>>>
    >>>> But what i want is:
    >>>> <head>
    >>>> <script>
    >>>> if (true)
    >>>> { location.replace('PCbase.html'); }
    >>>> endif
    >>>> </script>
    >>>> </head>
    >>>>
    >>>> What code IN HEAD section will replace/"jump"?
    >>>>
    >>>
    >>> You should really be in a web authoring or HTML
    >>> programming group for this, to tap into experts.
    >>> There aren't going to be enough of those programmers
    >>> here, to answer all questions.
    >>>
    >>> The way I look at it, the <body></body>
    >>> and <head></head> are two separate portions
    >>> of the web page, with different purposes. You
    >>> would not expect all the same capabilities to
    >>> exist in both. Do you know for a fact, that
    >>> head and body support all the same programming
    >>> constructs ? I don't know the answer to that.
    >>>
    >>> The definition of the location.replace is here...
    >>>
    >>> http://www.w3schools.com/jsref/met_loc_replace.asp
    >>>
    >>> and there are a few examples of HTML usage here.
    >>>
    >>> http://www.w3schools.com/html/html_examples.asp
    >>>
    >>> On that last page, look at the three examples for
    >>> some idea of what goes in the <head> section.
    >>> It doesn't look like a lot of "programming" goes
    >>> in there.
    >>>
    >>> HTML head Elements
    >>> ------------------
    >>>
    >>> Specify a title for a document
    >>> One default URL and target for all links on a page
    >>> Provide metadata for a document
    >>>
    >>> HTH,
    >>> Paul

    >> OK: will hunt for one.
    >> Found a way to "do it all" in the body, as follows:
    >>
    >> <script>
    >> // discover if browser is crappy Opera or crappy Safari
    >> str=navigator.userAgent; // Agent is unique for our purposes
    >> var sf=str.indexOf("Safari"); // found if browser is Chrome or Safari
    >> var ch=str.indexOf("Chrome"); // not found if browser is Safari
    >> var op=str.indexOf("Opera"); // unique for Opera
    >> var opt=1; // alternate shown below but not used
    >> ovar=window.opera; // is undefined if browser is not Opera
    >> if (!ovar) { opt=-1; } // unique for Opera
    >> // Safari gives sf=91,ch=-1; Opera gives sf=-1,op=7; Chrome gives
    >> sf=-1,ch>0.
    >> // Jump to different markup if crappy browser
    >> if (sf>0 && ch<0 || op>=0) { window.location.replace('Mobile.html'); }
    >> // ** NOTE treat crap as if mobile phone **
    >> // Code is a one-pager; there are mobile phones that struggle and die
    >> with
    >> // message "Page too large" "open media site"
    >>
    >> var isIE=str.indexOf("IE"); // not found in other browsers
    >> if (isIE>0) { window.location.replace('PCbase.html'); }
    >> var isMozilla=str.indexOf("Mozilla"); // Presumes in all variants;
    >> includes Netscape
    >> if (isMozilla>=0) { window.location.replace('PCbase.html'); }
    >> if (ch>=0) { window.location.replace('PCbase.html'); } // for Chrome
    >>
    >> document.write(str+"<BR>");
    >> document.write("At this point, browser is not Safari, Chrome, Opera or
    >> IE or Mozilla"+"<BR>");
    >> // So, ASSuME we have mobile phone browser
    >> // window.location.replace('Mobile.html');
    >> // -----^ always executes; previous valid .replace somehow bypassed
    >> </script>
    >>
    >> Above works fine, except as noted.
    >> NOT TESTED on a mobile phone (yet).

    >
    > But, are all the browsers honest ?
    >
    > http://www.nczonline.net/blog/2013/07/02/internet-explorer-11-dont-call-me-ie/
    >
    >
    > *******
    >
    > Make sure you're getting the best from your search engine. Since every web
    > developer will have done this stuff at one time or another, there will be
    > some "best practices" thoughts out there.
    >
    > https://developer.mozilla.org/en-US/docs/Browser_Detection_and_Cross_Browser_Support
    >
    >
    > http://stackoverflow.com/questions/1005153/auto-detect-mobile-browser-via-user-agent
    >
    >
    > http://detectmobilebrowsers.com/
    >
    > There's client or server sniffing, object or useragent determination.
    > More than one way to get there.
    >
    > HTH,
    > Paul

    "But, are all the browsers honest ?"
    Answer has been "NO" since the daze of Android mobile phones, where
    the navigator.userAgent string may be almost anything.

    Those other references are interesting, and it willtake me a while to
    digest the info.
    Thanks!
     
    Robert Baer, Mar 24, 2014
    #6
  7. Paul

    TeeJay1952 Guest

    On 3/24/2014 2:47 AM, Robert Baer wrote:
    > VanguardLH wrote:
    >> Robert Baer wrote:
    >>
    >>> The following stupid snippet works:
    >>> <body>
    >>> <script>
    >>> if (true)
    >>> { location.replace('PCbase.html'); }
    >>> endif
    >>> </script>
    >>> </body>
    >>>
    >>> But what i want is:
    >>> <head>
    >>> <script>
    >>> if (true)
    >>> { location.replace('PCbase.html'); }
    >>> endif
    >>> </script>
    >>> </head>
    >>>
    >>> What code IN HEAD section will replace/"jump"?

    >>

    I feel like you guys just saved the nanobots on Revolution!
    Tee Jay
     
    TeeJay1952, Mar 24, 2014
    #7
  8. Paul

    Paul Guest

    TeeJay1952 wrote:
    > On 3/24/2014 2:47 AM, Robert Baer wrote:
    >> VanguardLH wrote:
    >>> Robert Baer wrote:
    >>>
    >>>> The following stupid snippet works:
    >>>> <body>
    >>>> <script>
    >>>> if (true)
    >>>> { location.replace('PCbase.html'); }
    >>>> endif
    >>>> </script>
    >>>> </body>
    >>>>
    >>>> But what i want is:
    >>>> <head>
    >>>> <script>
    >>>> if (true)
    >>>> { location.replace('PCbase.html'); }
    >>>> endif
    >>>> </script>
    >>>> </head>
    >>>>
    >>>> What code IN HEAD section will replace/"jump"?
    >>>

    > I feel like you guys just saved the nanobots on Revolution!
    > Tee Jay


    See how easy web design is ?

    Get yourself a browser with a Composer window, and you
    can try stuff out for yourself. Seamonkey has a Composer window.

    http://www.seamonkey-project.org/

    Copy this into the Composer window while in source mode.
    (Click the "Source" tab at the bottom of the Composer window first.)
    And then you can view what it will look like as a web page.
    After you paste this in, try clicking the "Preview" tab to see
    what it looks like. What the code does.

    ------------------------------------------------------------------------
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    <title>Hello World!</title>
    </head>

    <body>
    <p>Hello World!
    </p>

    <p>Huh, <em>that's</em> not so tough. Now let's try something else.
    </p>
    </body>
    </html>
    ------------------------------------------------------------------------

    One thing I notice, is when I click the Source tab, to go back so
    I can do some more edits, it ruins my nice indenting. Guess it wants
    tabs or something.

    If an employer asks you what kind of web design experience
    you have, you can say "I designed Hello World!" :)

    Have fun,
    Paul
     
    Paul, Mar 24, 2014
    #8
  9. Paul

    Guest

    On 25/03/14 02:28, Paul wrote:

    <Snip>
    > Get yourself a browser with a Composer window, and you
    > can try stuff out for yourself. Seamonkey has a Composer window.
    >
    > http://www.seamonkey-project.org/
    >
    > Copy this into the Composer window while in source mode.
    > (Click the "Source" tab at the bottom of the Composer window first.)
    > And then you can view what it will look like as a web page.
    > After you paste this in, try clicking the "Preview" tab to see
    > what it looks like. What the code does.
    >
    > ------------------------------------------------------------------------
    > <html>
    > <head>
    > <meta http-equiv="content-type" content="text/html;
    > charset=ISO-8859-1">
    > <title>Hello World!</title>
    > </head>
    >
    > <body>
    > <p>Hello World!
    > </p>
    >
    > <p>Huh, <em>that's</em> not so tough. Now let's try something else.
    > </p>
    > </body>
    > </html>
    > ------------------------------------------------------------------------
    >
    > One thing I notice, is when I click the Source tab, to go back so
    > I can do some more edits, it ruins my nice indenting. Guess it wants
    > tabs or something.
    >
    > If an employer asks you what kind of web design experience
    > you have, you can say "I designed Hello World!" :)
    >
    > Have fun,
    > Paul


    In my SeaMonkey Composer, when I go back to the Source tab, it's still
    indented.

    Daniel
     
    , Mar 26, 2014
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bitman

    Redirect LPT1 to COM4 for Bluetooth printing

    Bitman, Jun 26, 2004, in forum: Wireless Networking
    Replies:
    3
    Views:
    12,987
    Patrick Sears [MSFT]
    Jul 22, 2004
  2. Splibbilla
    Replies:
    2
    Views:
    4,747
    Splibbilla
    Jul 23, 2005
  3. Replies:
    9
    Views:
    3,446
    Walter Roberson
    Nov 18, 2003
  4. Andrew Albert

    Redirect Port for a particular IP

    Andrew Albert, Dec 6, 2003, in forum: Cisco
    Replies:
    1
    Views:
    3,687
  5. Matt

    Redirect DNS on 3640

    Matt, Dec 31, 2003, in forum: Cisco
    Replies:
    1
    Views:
    2,746
    Walter Roberson
    Dec 31, 2003
Loading...

Share This Page