Results 1 to 7 of 7

Thread: change stylesheet upon page url

  1. #1
    Join Date
    Feb 2005
    Posts
    153
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default change stylesheet upon page url

    Hey, am a bit of a newbie to asp so go gentle!

    I have 2 domain names: www.tascomms.co.uk and www.tascomms.mobi, they both point to the same site.

    What I want is when people go to the site through the .co.uk domain they are issued one style sheet and if they go through the .mobi domain they are issued another. This is my code so far:


    Code:
    <% 
    domainname = Request.ServerVariables("SERVER_NAME") 
    
    response.write domainname
    
    IF domainname = www.tascomms.co.uk THEN
    %>
    <link rel="stylesheet" href="css/screen.css" type="text/css" media="screen"  />
    <%
    END IF
    
    IF domainname = www.tascomms.mobi THEN
    %>
    <link rel="stylesheet" href="css/handheld.css" type="text/css" media="handheld"  />
    <%
    END IF
    
    %>

    This keeps bringing up the following error:



    Microsoft VBScript runtime error '800a01a8'
    Object required: 'domainname' /aboutus2.asp, line 18

    can anyone help?

    cheers

  2. #2
    Join Date
    Feb 2004
    Posts
    4,903
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    You need to quote your strings and declare your variables:

    Code:
    <%
    Dim domainname
    domainname = Request.ServerVariables("SERVER_NAME") 
    
    response.write domainname
    
    IF domainname = "www.tascomms.co.uk" THEN
    %>
    <link rel="stylesheet" href="css/screen.css" type="text/css" media="screen"  />
    <%
    END IF
    
    IF domainname = "www.tascomms.mobi" THEN
    %>
    <link rel="stylesheet" href="css/handheld.css" type="text/css" media="handheld"  />
    <%
    END IF
    
    %>
    Also - here is cleaner, failsafe code:

    Code:
    <%
    Dim DomainName, StyleSheet
    DomainName = LCase(Request.ServerVariables("SERVER_NAME"))
    If Left(DomainName, 4) = "www." Then DomainName = Right(DomainName, Len(DomainName) - 4)
    
    Select Case DomainName
    	Case "tascomms.co.uk"
    		StyleSheet = "screen"
    	Case "tascomms.mobi"
    		StyleSheet = "handheld"
    End Select
    %>
    
    <link rel="stylesheet" href="css/<%=StyleSheet%>.css" type="text/css" media="<%=StyleSheet%>"  />
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

  3. The Following User Says Thank You to Warren Ashcroft For This Useful Post:

    RFH Reseller: Space Cowboy (5th February 2008)

  4. #3
    Join Date
    Mar 2005
    Location
    Isle of Man
    Posts
    1,261
    Thanks
    3
    Thanked 24 Times in 24 Posts

    Default

    I am not sure why you would want to do what you are doing when simply having
    Code:
    <link rel="stylesheet" href="css/screen.css" type="text/css" media="screen"  />
    <link rel="stylesheet" href="css/handheld.css" type="text/css" media="handheld"  />
    would mean each device would get the right style sheet regardless of the domain TLD.

    If you wanted to force mobile users to see the site on the .mobi domain and other users on the co.uk I'd do it as a separate bit of code that simply redirects from one to the other.

  5. #4
    Join Date
    Feb 2005
    Posts
    153
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default

    Thanks Warren thats great!

    The reason for this is 2 reasons, the first is that not all browsers on handheld devices recognise the "handheld" stylesheet and will just use the "screen" stylesheet.

    This will ensure that if someone types in the .mobi domain name they will see it with the "handheld" stylesheet regardless of wether or not their browser supports them.

    Also I want people to view the website on a PC as a demo as to how it would look on a handheld device.

  6. #5
    Join Date
    Feb 2005
    Posts
    153
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default

    Actually what I need (using Warrens code) is this:

    Code:
     
    <%
    Dim DomainName, StyleSheet
    DomainName = LCase(Request.ServerVariables("SERVER_NAME"))
    If Left(DomainName, 4) = "www." Then DomainName = Right(DomainName, Len(DomainName) - 4)
    
    Select Case DomainName
    Case "tascomms.co.uk"
    StyleSheet = "screen"
    Case "tascomms.mobi"
    StyleSheet = "handheld"
    End Select
    %>
    
    <link rel="stylesheet" href="css/<%=StyleSheet%>.css" type="text/css" media="screen"  />
    
    <link rel="stylesheet" href="css/handheld.css" type="text/css" media="handheld"  />

    So if someone goes into tascomms.co.uk they will always be presented with the true screen version, unless they view on a handheld device that supports the handheld style sheet in which case they will get the handheld style sheet.

    But if someone goes onto tascomms.mobi they will ALWAYS see the site with the handheld stylesheet regardless of their device and if their browser supports handheld stylesheets.

  7. #6
    Join Date
    May 2004
    Location
    NewYork, USA
    Posts
    175
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Default

    Code:
     
    <link rel="stylesheet" href="css/<%=StyleSheet%>.css" type="text/css" media="<%=StyleSheet%>"  />
    I want to use this code for selecting language file with server side include.
    <!--#include file="english.asp"-->


    it that possible to use variable on this line
    <!--#include file="english.asp"-->


    may be something like this:
    <!--#include file="' & variable & '"-->

  8. #7
    Join Date
    Feb 2004
    Posts
    4,903
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    Quote Originally Posted by HostCan View Post
    Code:
     
    <link rel="stylesheet" href="css/<%=StyleSheet%>.css" type="text/css" media="<%=StyleSheet%>"  />
    I want to use this code for selecting language file with server side include.
    <!--#include file="english.asp"-->


    it that possible to use variable on this line
    <!--#include file="english.asp"-->


    may be something like this:
    <!--#include file="' & variable & '"-->
    No, include files are "included" before any ASP code is executed.

    So you can do this:

    Select Case Langauge
    Case "EN"
    <!--#include file="english.asp"-->
    Case "FR"
    <!--#include file="french.asp"-->
    End Select
    Note: both english and french files will be loaded and included, however only one will run.
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

  9. The Following User Says Thank You to Warren Ashcroft For This Useful Post:

    RFH Reseller: HostCan (7th March 2008)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Server locale change
    By Lord1e in forum General Technical Support
    Replies: 6
    Last Post: 22nd June 2007, 10:41 AM
  2. Time for a change??
    By AndyHearne in forum Garble
    Replies: 12
    Last Post: 26th February 2006, 10:30 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •