Chamando função javascript [Resolvido]

14 respostas
R

Preciso de ajuda

precisa chamar a função teste() no link so q nao consigo. [Resolvido]

function abrir() {

           var width = 150;
           var height = 250;
           var left = 99;
           var top = 99;
           window.open('comentario.php','janela', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

		 }

		function _set_interface() {			
			// Aplique a marcação HTML em tag body
			$('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="' + settings.imageLoading + '"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="' + settings.imageBtnClose + '"></a></div></div></div><div id="comentarios"><a href="[b]Aqui preciso chamar a funçao abrir[/b]()" style="padding-top:10px;" target="_blank">Obah posso comentar</a></div></div>');

14 Respostas

D

Edite teu tópico e inclua o código dentro das tags [code]

R

Pronto drsmachado .

D
<a href="#" onclick="abrir();" style="padding-top:10px;" target="_blank">Obah posso comentar</a>

É isso.

R

Cara ja tinha feito isso,

nao da certo.

D

Vamos por partes.
Isso fará com que a função seja chamada.
Debugue-a e veja como você entra na função.
Agora, se a função está ou não rodando, é outra história.
Aliás, testei e está funcionando, abre o popup, porém, como existem outras coisas envolvidas, pode ser isto que está te atrapalhando.

R
olha o codigo inteiro para vc ver

(function($) {
	
	$.fn.lightBox = function(settings) {
		// Settings to configure the jQuery lightBox plugin how you like
		settings = jQuery.extend({
			// Configuration related to overlay
			overlayBgColor: 		'#000',		// (string) Background color to overlay; inform a hexadecimal value like: #RRGGBB. Where RR, GG, and BB are the hexadecimal values for the red, green, and blue values of the color.
			overlayOpacity:			0.8,		// (integer) Opacity value to overlay; inform: 0.X. Where X are number from 0 to 9
			// Configuration related to navigation
			fixedNavigation:		false,		// (boolean) Boolean that informs if the navigation (next and prev button) will be fixed or not in the interface.
			// Configuration related to images
			imageLoading:			'images/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
			imageBtnPrev:			'images/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
			imageBtnNext:			'images/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
			imageBtnClose:			'images/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
			imageBlank:				'images/lightbox-blank.gif',			// (string) Path and the name of a blank image (one pixel)
			teste:                  'comentario.php',
			// Configuration related to container image box
			containerBorderSize:	10,			// (integer) If you adjust the padding in the CSS for the container, #lightbox-container-image-box, you will need to update this value
			containerResizeSpeed:	400,		// (integer) Specify the resize duration of container image. These number are miliseconds. 400 is default.
			// Configuration related to texts in caption. For example: Image 2 of 8. You can alter either "Image" and "of" texts.
			txtImage:				'Imagem',	// (string) Specify text "Image"
			txtOf:					'de',		// (string) Specify text "of"
			// Configuration related to keyboard navigation
			keyToClose:				'27',		// (string) (c = close) Letter to close the jQuery lightBox interface. Beyond this letter, the letter X and the SCAPE key is used to.
			keyToPrev:				'p',		// (string) (p = previous) Letter to show the previous image
			keyToNext:				'n',		// (string) (n = next) Letter to show the next image.
			// Don´t alter these variables in any way
			imageArray:				[],
			activeImage:			0
		},settings);
		// Caching the jQuery object with all elements matched
		var jQueryMatchedObj = this; // This, in this context, refer to jQuery object
		/**
		 * Initializing the plugin calling the start function
		 *
		 * @return boolean false
		 */
		function _initialize() {
			_start(this,jQueryMatchedObj); // This, in this context, refer to object (link) which the user have clicked
			return false; // Avoid the browser following the link
		}
		/**
		 * Start the jQuery lightBox plugin
		 *
		 * @param object objClicked The object (link) whick the user have clicked
		 * @param object jQueryMatchedObj The jQuery object with all elements matched
		 */
		function _start(objClicked,jQueryMatchedObj) {
			// Hime some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
			$('embed, object, select').css({ 'visibility' : 'hidden' });
			// Call the function to create the markup structure; style some elements; assign events in some elements.
			_set_interface();
			// Unset total images in imageArray
			settings.imageArray.length = 0;
			// Unset image active information
			settings.activeImage = 0;
			// We have an image set? Or just an image? Let´s see it.
			if ( jQueryMatchedObj.length == 1 ) {
				settings.imageArray.push(new Array(objClicked.getAttribute('href'),objClicked.getAttribute('title')));
			} else {
				// Add an Array (as many as we have), with href and title atributes, inside the Array that storage the images references		
				for ( var i = 0; i < jQueryMatchedObj.length; i++ ) {
					settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'),jQueryMatchedObj[i].getAttribute('title')));
				}
			}
			while ( settings.imageArray[settings.activeImage][0] != objClicked.getAttribute('href') ) {
				settings.activeImage++;
			}
			// Call the function that prepares image exibition
			_set_image_to_view();
		}
		/**
		 * Create the jQuery lightBox plugin interface
		 *
		 * The HTML markup will be like that:
			<div id="jquery-overlay"></div>
			<div id="jquery-lightbox">
				<div id="lightbox-container-image-box">
					<div id="lightbox-container-image">
						<img src="../fotos/XX.jpg" id="lightbox-image">
						<div id="lightbox-nav">
							<a href="#" id="lightbox-nav-btnPrev"></a>
							<a href="#" id="lightbox-nav-btnNext"></a>
						</div>
						<div id="lightbox-loading">
							<a href="#" id="lightbox-loading-link">
								<img src="../images/lightbox-ico-loading.gif">
							</a>
						</div>
					</div>
				</div>
				<div id="lightbox-container-image-data-box">
					<div id="lightbox-container-image-data">
						<div id="lightbox-image-details">
							<span id="lightbox-image-details-caption"></span>
							<span id="lightbox-image-details-currentNumber"></span>
						</div>
						<div id="lightbox-secNav">
							<a href="#" id="lightbox-secNav-btnClose">
								<img src="../images/lightbox-btn-close.gif">
							</a>
						</div>
					</div>
				</div>
			</div>
		 *
		 */
		 function abrir(url) {
           window.open(url,'janela', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes,status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
		 }

		function _set_interface() {			
			// Aplique a marcação HTML em tag body
			$('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="' + settings.imageLoading + '"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="' + settings.imageBtnClose + '"></a></div></div></div><div id="comentarios"><a class="comentario" onclick="abrir("comentario.php");" target="_blank" href="#">Obah posso comentar</a></div></div>');	
			// Pega os tamanhos de página
			var arrPageSizes = ___getPageSize();
			// Estilo / overlay e mostrá-lo
			$('#jquery-overlay').css({
				backgroundColor:	settings.overlayBgColor,
				opacity:			settings.overlayOpacity,
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]
			}).fadeIn();
			// Pega rolagem página
			var arrPageScroll = ___getPageScroll();
			// Calcula superior e deslocamento à esquerda para o objeto div jquery lightbox, e mostrá-lo
			$('#jquery-lightbox').css({
				top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
				left:	arrPageScroll[0]
			}).show();
			// Atribuindo eventos de clique em elementos para fechar sobreposição
			//$('#jquery-overlay,#jquery-lightbox').click(function() {
			//	_finish();									
			//});
			 // Atribuir a função _finish à coleção de carregamento-link e coleção-secNav-btnClose objetos
			$('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function() {
				_finish();
				return false;
			});
			// Se a janela foi redimensionada, calcular as dimensões de sobreposição novos
			$(window).resize(function() {
				// Get page sizes
				var arrPageSizes = ___getPageSize();
				// Style overlay and show it
				$('#jquery-overlay').css({
					width:		arrPageSizes[0],
					height:		arrPageSizes[1]
				});
				// Get page scroll
				var arrPageScroll = ___getPageScroll();
				// Calculate top and left offset for the jquery-lightbox div object and show it
				$('#jquery-lightbox').css({
					top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
					left:	arrPageScroll[0]
				});
			});
		}
R

Alguem pode me ajudar ?

D

Se está com pressa, pode adiantar o pagamento, assim pode cobrar pressa.
Vamos lá, veja que existe um erro no modo como você chama e é o que difere a forma que orientei da que está usando.

<a class="comentario" onclick="abrir("comentario.php");" target="_blank" href="#">Obah posso comentar</a>

Perceba que no evento onclick você coloca uma chamada a uma função chamada abrir e passa o parâmetro comentario.php. A assinatura da função que você possui, chamada abrir não espera nenhum argumento, logo, nunca será acionada.
Eu sugeri que fizesse

<a class="comentario" onclick="abrir();" target="_blank" href="#">Obah posso comentar</a>

Note que eu chamo abrir() sem argumentos. Isso fará com que a função seja reconhecida e executada.
Ou você muda a função para

function abrir(argumento){
//faz algo aqui
}

Ou altera o evento onclick da âncora como sugeri anteriormente.

Outro detalhe é que

<a class="comentario" onclick="abrir("comentario.php");" target="_blank" href="#">Obah posso comentar</a>

Quando eu possuo um atributo HTML e seu conteúdo é referenciado com aspas duplas “” e preciso referenciar algo a este valor (como um argumento para função) eu uso aspas simples

<a class="comentario" onclick="abrir('comentario.php');" target="_blank" href="#">Obah posso comentar</a>

Ou uso um caractere indicando que estas aspas serão “escapadas”

<a class="comentario" onclick="abrir(\"comentario.php\");" target="_blank" href="#">Obah posso comentar</a>

Caso contrário, o processamento pode ser comprometido.

R
meu amigo desculpa pela presa mais e pq ja to 3 dias com isso.

ja fiz isso tudo q vc me oriento.

deixa eu te explicar melhor 

aquele codigo e uma ligth box que abre fotos ai nela to colocando aquele link para chamar uma janela pra fazer comentarios.

ai quando chamo esse codigo ele chama e a pagina q ta por tras da ligth box

<a class="comentario" onclick="abrir(comentario.php);" href="#">Obah posso comentar</a>
que e essa url ai http://127.0.0.1/portalobah/?pg=evento&pageid=12#
D
Bom, o tópico foi criado apenas hoje... Enfim, veja como está a função para abrir a janela de comentários:
function abrir() {  
  
           var width = 150;  
           var height = 250;  
           var left = 99;  
           var top = 99;  
           window.open('comentario.php','janela', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');  
  
         }
Veja que ela não possui argumentos. Se você insiste em usar argumentos, precisa modifica-la para isto
function abrir(seu_argumento_aqui) {  
  
           var width = 150;  
           var height = 250;  
           var left = 99;  
           var top = 99;  
           window.open(seu_argumento_aqui,'janela', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');  
  
         }
Note que as modificações que fiz foram, receber parâmetro e este parâmetro será o primeiro item da função open.
R

entao drsmachado

ja fiz com argumento e sem argumento

nao funciona nao sei pq ?

D

Vamos fazer o seguinte, descreva melhor esse não funciona. Por que isso já está me enchendo.
Tenho total e plena convicção que está fazendo algo muito errado. Isto é um processo simples, não tem nada de complexo.
Debugou como eu disse? O que aconteceu? Usa mozilla firefox? Chrome?

R
obrigado pela atençao

ja resolvi ja...

faltava esse codigo ai

$('#comentario').click(function() {
				abrir();
				return false;
			});
D

Da forma como estava implementando, faz sentido.
Edite o tópico original e, no título, coloque [RESOLVIDO] antes do mesmo.

Criado 20 de junho de 2012
Ultima resposta 20 de jun. de 2012
Respostas 14
Participantes 2