Jump to content

Recommended Posts

Posted

olhem tipo eu queria que me aranjassem um code para tipo: temos uma textbox e pomos um determinado texto e ele redirecta para o ke escrevemos... allguem me aranja?

ex:

Ponha a pass

____________________

|Teste                          |

___

|ok |

Ao carregar ok ia para a pasta teste ou para o ficheiro texte.htm

http://www.neopt.org <- O meu blog xD
Posted

Ois

Para este exemplo criei 2 ficheiros html - Teste1.html e Teste2.html, e uma pasta - Teste3, tudo no mm sitio(mm caminho).

Teste1.html

<html>
<head>
<title>Teste1</title>
<script language="JavaScript">
function HandleClick()
{
if (Input1.value == "")
   alert("Por favor insira o nome de um ficheiro\nhtml ou de uma pasta");
else
{
   var fso, DocPath, ParentFolder;
   fso = new ActiveXObject("Scripting.FileSystemObject");
   DocPath = document.location.pathname;
   ParentFolder = fso.GetParentFolderName(DocPath);
   ParentFolder = ParentFolder.replace(/\//, '');
   ParentFolder = ParentFolder.replace(/\\/g,'/');
   if (fso.FolderExists(ParentFolder+"/"+Input1.value))
      window.open(Input1.value, "_self");
   else
      if (fso.FileExists(ParentFolder+"/"+Input1.value+".html"))
         window.open(Input1.value+".html", "_self");
      else
         alert("Nao existe nenhum ficheiro html ou pasta com esse nome.");
}
}
</script>
</head>
<body>
<input id="Input1" type="text" value="" />
<input type="button" value="Click!" onclick="HandleClick();" />
</body>
</html>

Teste2.html

<html>
<head>
<title>Teste2</title>
</head>
<body>
Teste2
</body>
</html>

Eu neste codigo estou a ir buscar o caminho onde esta o Teste1.html e quando o user insere um texto so estou a ver se existe alguma pasta

ou ficheiro html com esse nome nesse caminho.

Se nao escrever nada na caixa de texto da um alert com o seguinte texto "Por favor insira o nome de um ficheiro html ou de uma pasta",

se escrever um texto e nao existir nenhuma pasta ou ficheiro html com o nome igual a esse texto da um alert com o seguinte

texto "Nao existe nenhum ficheiro html ou pasta com esse nome.", se escrever "Teste2" ou "teste2" vai abrir o ficheiro Teste2.html, se

escrever "Teste3" ou "teste3" vai para a pasta Teste3.

Mas atençao como ja disse acima os ficheiros html e as pastas k queres k o user possa a brir teem de estar todos no mm sitio(mm caminho).

Espero ter ajudado.

Se a vida te voltar as costas aproveita e apalpa-lhe o cu.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.