/    Sign up×
Community /Pin to ProfileBookmark

CSS Swap Script

Ive made a simple Javascript Function that will swap the CSS source file, and change the page properties, The Code works in Mozilla2, and swaps the page but in IE7 it doesn’t work, Im pretty Sure it works in IE6, was testing it yesterday. I placed alert() messages around to show the css reference which works in mozilla but not IE7 in IE it shows nothing at all not even the original reference.

Code Below
<head>
<script language=”JavaScript” type=”text/JavaScript”>
function Swap(Path) {

alert(document.getElementById(‘Design’).innerHTML);
document.getElementById(‘Design’).innerHTML='<link rel=”stylesheet” type=”text/css” href=”CSS/’+Path+'” /><!–[if IE 6]><link rel=”stylesheet” type=”text/css” href=”CSS/ie6’+Path+'”/><![endif]–><!–[if IE 7]><link rel=”stylesheet” type=”text/css” href=”CSS/ie7’+Path+'” /><![endif]–>’;

}
</script>

<div id=”Design”>
<link rel=”stylesheet” type=”text/css” href=”CSS/Tourism.css” />
<!–[if IE 6]>
<link rel=”stylesheet” type=”text/css” href=”CSS/ie6Tourism.css” />
<![endif]–>
<!–[if IE 7]>
<link rel=”stylesheet” type=”text/css” href=”CSS/ie7Tourism.css” />
<![endif]–>
</div>

</head>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@NatdripMay 18.2007 — hey Nate

[code=html]
function switchpop(t,obj){
agt=navigator.userAgent.toLowerCase();


obj = document.getElementById(obj)
var newO=document.createElement('input');

newO.setAttribute('type','text');
var tom = t.innerHTML;
if(tom=="&nbsp;"){
newO.setAttribute('value'," ",0);
}else{
newO.setAttribute('value',t.innerHTML,0);
}
newO.setAttribute('class',obj.getAttribute('class'),0);
newO.setAttribute('name',obj.getAttribute('name'),0);
newO.setAttribute('Id',obj.getAttribute('Id'),0);
newO.setAttribute('maxlength',obj.getAttribute('maxlength'),0);
newO.setAttribute('size',obj.getAttribute('size'),0);
obj.parentNode.replaceChild(newO,obj);
newO.focus();

t.style.display='none';
}
[/code]


you can use something like this

I built this function a short while ago because I was running into the same problem. it basically creates a node object by coping one rewrites the node tags then deletes the old.

here is a working example...
[code=html]
<table>
<tr>
<td>Zip: <input type="hidden" id="Zip" name="Zip" maxlength="5" size="6" class="h" value="<%=Zip%>" /><span onclick="switchpop(this,'Zip');" class="spanBut"><%=Zip%></span></td>
</tr>
</table>
[/code]
×

Success!

Help @Nate1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...