0

suppose currently by browser url is "www.xyz.com" and my href="/css/home.css". Now my requirement is that, if the url changes to "www.xyza.com" or if it changes to say something like "www.xyzb.com " then my href should also change with the url provided to say href="/css/home_a.css" and href="/css/home_b.css" respectively.

Can someone please tell me how can i achieve this?

1
  • 1
    What are you trying to achieve, could you provide an example? I dont see any sense by doing this Commented Jul 25, 2011 at 11:19

3 Answers 3

1

you can get the current location with document.write (document.location.href); and then change the href of the css with jquery,

$("a").attr("href", "/css/home_a.css")

Sign up to request clarification or add additional context in comments.

Comments

0

You can use server-side scripting to generate the right link. You didn't mention what you're using.

Or you could look at hostname and change the links with Javascript:

switch(document.location.host) {
    case "www.google.com": alert("Google"); break;
    default: alert("Other!");
}

Comments

0

if you are trying to make a style switcher on the same domain, there are 2000 ways to do that, like for example easy to adapt to your specific question (unclear to me):

In your main page

<head>
<!-- bla bla -->
<link rel="stylesheet" media="screen, projection" type="text/css" id="css" href="<?php echo switch_style();?>" />
<head>

In your style switch function

function build_css($style) {
    $css_file='style/'.$style.'/style.css'; // providing here your css path
    return $css_file;
}
function switch_style() {

    $style_dispo = array('default','style1','style2','style3','style4','style5');

    $current_style = ((isset($_SESSION['nav_style'])) AND ($_SESSION['nav_style'] != '')) ? $_SESSION['nav_style'] : 'default';

        // There you can adapt the style switch to your need, for example based on the $_SERVER(REQUEST_URI) in your case i/o a GET test case like here
    $new_style = (isset($_GET['style'])) ? $_GET['style'] : '';

    // style change
    if (($new_style != $current) AND ($new_style !=''))
    {
        if (in_array($new_style,$style_dispo))
        {
            $style= $new_style;
            $_SESSION['nav_style']=$style;
        }
        else
        {
            $style ='default';
            $_SESSION['nav_style']=$style;
        }
    }
    else
    {
        $style = $current_style;
        $_SESSION['nav_style'] = $style;
    }
    return build_css($style);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.