javascript:var link to php

Discussion in 'PHP' started by mediaroot, Jun 19, 2011.

  1. #1
    Hi guys,

    I was wondering if there is a solution to have call for action button in php with a javascript:var into it. as you know it will break the php codes.

    Here is a sample of a bookmarklet link:

    javascript:var%20imgstr='';var%20reg=new%20RegExp('&');%20%20%20%20%20%20%20%20%20%20%20%20for(i=0;i<document.images.length;i++){%20%20%20%20%20%20%20%20%20%20%20%20%20%20if(!%20reg.test(document.images[i].src)){%20%20%20%20%20%20%20%20%20%20%20%20%20%20imgstr%20=%20imgstr%20+%20document.images[i].src%20+%20',';%20%20%20%20%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20%20%20var%20d=document;%20%20%20%20%20%20%20%20%20%20%20%20var%20w=window;%20%20%20%20%20%20%20%20%20%20%20%20var%20e=w.getSelection;%20%20%20%20%20%20%20%20%20%20%20%20var%20k=d.getSelection;%20%20%20%20%20%20%20%20%20%20%20%20var%20x=d.selection;%20%20%20%20%20%20%20%20%20%20%20%20var%20s=(e?e():(k)?k():(x?x.createRange().text:0));%20%20%20%20%20%20%20%20%20%20%20%20var%20f='http://www.website.com/quickpost.php';%20%20%20%20%20%20%20%20%20%20%20%20var%20l=d.location;%20%20%20%20%20%20%20%20%20%20%20%20var%20e=encodeURIComponent;%20%20%20%20%20%20%20%20%20%20%20%20var%20p='?imagez='+imgstr;%20%20%20%20%20%20%20%20%20%20%20%20var%20u=%20'&u='%20+%20e(l.href);%20%20%20%20%20%20%20%20%20%20%20%20var%20t=%20'&t='%20+%20e(d.title);%20%20%20%20%20%20%20%20%20%20%20%20var%20s=%20'&s='%20+%20e(s);%20%20%20%20%20%20%20%20%20%20%20%20var%20g=%20f+p+u+t+s;%20%20%20%20%20%20%20%20%20%20%20%20function%20a(){%20%20%20%20%20%20%20%20%20%20%20%20%20%20if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=700,height=500')){%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20l.href=g;%20%20%20%20%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20%20%20if(/Firefox/.test(navigator.userAgent)){%20%20%20%20%20%20%20%20%20%20%20%20%20%20setTimeout(a,0);%20%20%20%20%20%20%20%20%20%20%20%20}else{%20%20%20%20%20%20%20%20%20%20%20%20%20%20a();%20%20%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20%20%20void(0);
    
    Code (markup):
    Thank you in advance.
     
    mediaroot, Jun 19, 2011 IP
  2. WiserX

    WiserX Peon

    Messages:
    16
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It will be helpful, if you explain in details...

    I'm using some methods like this...
     
    WiserX, Jun 21, 2011 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,899
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #3
    Lets simplify this and ask a question or two

    your javascript is actually this
    var imgstr='';
    var reg=new RegExp('&'); 
    for(i=0;i<document.images.length;i++){
    	if(!reg.test(document.images[i].src)){
    		imgstr=imgstr+document.images[i].src+',';
    	}
    	var d=document;
    	var w=window;
    	var e=w.getSelection;
    	var k=d.getSelection;
    	var x=d.selection;
    	var s=(e?e():(k)?k():(x?x.createRange().text:0));
    	var f='http://www.website.com/quickpost.php';
    	var l=d.location;
    	var e=encodeURIComponent;
    	var p='?imagez='+imgstr;
    	var u= '&u=' + e(l.href);            
    	var t= '&t=' + e(d.title);            
    	var s= '&s=' + e(s);            
    	var g= f+p+u+t+s;            
    	function a(){              
    		if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=700,height=500')){                
    			l.href=g;              
    		}            
    	}            
    	if(/Firefox/.test(navigator.userAgent)){              
    		setTimeout(a,0);            
    	}
    	else{              
    		a();
    	}
    }
    void(0);
    Code (markup):
    Why don't you create a function with all that code and just call it from the onclick event?
    It will be easier to debug and maintain. All those %20's were totally unnecessary.
     
    sarahk, Jun 21, 2011 IP