javascript toggle
- Started
- Last post
- 7 Responses
- AD
does anybody know how to write a script or point to an existing script that lets you toggle between 2 domains set up with the same file names- in other
words if i had :and I clicked on the toggle i'd go to
I can't use asp or php etc.
any help is appreciated
- BlueTree0
Are you saying that you want to do this all on the server.... without just having a link to the other site pointing to the same html file
- AD0
ya sorry I realize i wasn't clear
basically i want to write a javascript so that when you call the function with the onclick it switches to the same file in the same directory of a different domain
so if you had domain_a/helo.html and you called the function - you'd got to domain_b/helo.html
depending on wahtever the one file is it wil go to the same file but on a different domain
- BlueTree0
I think it would have to be server side... other than that I have no clue.
- o0o0
it can be done client side... as long as you know the domains in question on the client side. Just get the url, split it along the "/", then rebuild it with the other domain, then window.open() with the new url...
- morphosis0
Wow. I can not get my head around the effect you try to achieve
- kappa0
If I have this right, you want to LINK to a file that might be on one of a number of servers, right?
that's not too hard at all.
<a href="void(0)" onClick="doToggle('the/file/here...
the SIMPLE js:
tState = true;
function doToggle(fileURL) {
if(tState) document.location.href = 'http://server1.com/' + fileURL;
else document.location.href = 'http://server2.com/' + fileURL;tState != tState;
}this is the simple version, it can be far my dynamic, email me if you need more.
- kappa0
that script AUTOMATICALLY toggles between one server and the other. You can easy change this by having a separate function change the "tState" from true to false
function setState(trueFalse) {
tState = trueFalse;
}setState(true);
//or
setState(false)