Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Weid

com JavaScript para URL

Recommended Posts

estou desenvolvendo um sistema em php/mysql de noticias..

e coloquei umas funcoes de javascript para formatação do texto.. todas funcionaram perfeitamente bem..

mas quando resolvi colocar uma funcao para colocar um link na noticia como essa que tem aqui no proprio forum nao funcionou como eu queria.. ele sempre lança a URL no final do que eu to escrevendo.. e não onde eu marquei para aparecer..

vou colocar o codigo aqui.. se alguem poder me ajudar eu vou agradecer muito..

 

function bbcode2(acao){	var revisedMessage;	var currentMessage = document.post.noticia.value;	if (acao == "URL") {  var thisURL = prompt("Entre com a URL que você gostaria de adicionar", "http://");  var thisTitle = prompt("Entre com o titulo da URL", "Seu Titulo");  var urlBBCode = "[URL="+thisURL+"=URL]"+thisTitle+"[/URL]";  revisedMessage = currentMessage+urlBBCode;  document.post.noticia.value=revisedMessage;  document.post.noticia.focus();  return;	}}

a chamada é com esse butao..

<input type="button" class="button" value="URL"  onclick="javascript:bbcode2('URL')";>

Compartilhar este post


Link para o post
Compartilhar em outros sites

As funções para inserir no meio do texto, creio que são estas

 

ASP

[*]function tag_url() {

 

[*] var FoundErrors = '';

 

[*] var enterURL  prompt(text_enter_url, "http://");

 

[*] var enterTITLE prompt(text_enter_url_name, "My Webpage");

 

[*]

 

[*] if (!enterURL) {

 

[*] FoundErrors +" " + error_no_url;

 

[*] }

 

[*]

 

[*] if (!enterTITLE) {

 

[*] FoundErrors +" " + error_no_title;

 

[*] }

 

[*]

 

[*] if (FoundErrors) {

 

[*] alert("Error!"+FoundErrors);

 

[*] return;

 

[*] }

 

[*]

 

[*] doInsert(""+enterTITLE+""""false);

 

[*]}

 

[*]

 

[*]function doInsert(ibTag, ibClsTag, isSingle) {

 

[*] var isClose false;

 

[*] var obj_ta fombj.Post;

 

[*]

 

[*] //----------------------------------------

 

[*] // It's IE!

 

[*] //----------------------------------------

 

[*] if ( (ua_vers >= 4) && is_ie && is_win) {

 

[*] if (obj_ta.isTextEdit) {

 

[*] obj_ta.focus();

 

[*] var sel document.selection;

 

[*] var rng sel.createRange();

 

[*] rng.colapse;

 

[*]

 

[*] if((sel.type ="Text" || sel.type ="None") && rng != null) {

 

[*] if(ibClsTag !"" && rng.text.length > 0) ibTag +rng.text + ibClsTag;

 

[*] else if(isSingle) isClose true;

 

[*] rng.text = ibTag;

 

[*] }

 

[*] } else {

 

[*] if(isSingle) {

 

[*] isClose true;

 

[*] }

 

[*]

 

[*] obj_ta.value += ibTag;

 

[*] }

 

[*] }

 

[*]

 

[*] //----------------------------------------

 

[*] // It's MOZZY!

 

[*] //----------------------------------------

 

[*] else if ( obj_ta.selectionEnd ) {

 

[*] var ss obj_ta.selectionStart;

 

[*] var st obj_ta.scrollTop;

 

[*] var es obj_ta.selectionEnd;

 

[*]

 

[*] if (es <= 2) {

 

[*] es obj_ta.textLength;

 

[*] }

 

[*]

 

[*] var start = (obj_ta.value).substring(0, ss);

 

[*] var middle = (obj_ta.value).substring(ss, es);

 

[*] var end = (obj_ta.value).substring(es, obj_ta.textLength);

 

[*]

 

[*] //-----------------------------------

 

[*] // text range?

 

[*] //-----------------------------------

 

[*] if (obj_ta.selectionEnd - obj_ta.selectionStart > 0) {

 

[*] middle = ibTag + middle + ibClsTag;

 

[*] } else {

 

[*] middle = ibTag + middle;

 

[*]

 

[*] if (isSingle) {

 

[*] isClose true;

 

[*] }

 

[*] }

 

[*]

 

[*] obj_ta.value = start + middle + end;

 

[*] var cpos = ss + (middle.length);

 

[*] obj_ta.selectionStart = cpos;

 

[*] obj_ta.selectionEnd  = cpos;

 

[*] obj_ta.scrollTop = st;

 

[*] }

 

[*]

 

[*] //----------------------------------------

 

[*] // It's CRAPPY!

 

[*] //----------------------------------------

 

[*] else {

 

[*] if (isSingle) {

 

[*] isClose true;

 

[*] }

 

[*]

 

[*] obj_ta.value += ibTag;

 

[*] }

 

[*]

 

[*] obj_ta.focus();

 

[*] return isClose;

 

[*]}

 

uso:

 

<input type="button" accesskey="h" value="URL" onclick="tag_url()"  name="url" />

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.