0

why does the following decoded script not work? The original code seems to run just fine.

javascript:(function(s){try{s=document.selection.createRange().text}catch(_)  {s=document.getSelection()}prompt('State the question and answer below.','Q.' s '')})

original code:

javascript:%28function%28s%29%7Btry%7Bs=document.selection.createRange%28%29.text%7Dcatch%28_%29%7Bs=document.getSelection%28%29%7Dprompt%28%27State the question and answer below.%27,%27Q.%27+s+%27%27%29%7D%29%28%29

Thanks very much in advance.

query
  • 27
  • 1
  • 2
  • 4

2 Answers2

1

It decoded the + sign to a space, try this:

javascript:(function(s){try{s=document.selection.createRange().text}catch(_)  {s=document.getSelection()}prompt('State the question and answer below.','Q.'+s+'')})

The difference: change ' s ' to this '+s+'

P1nGu1n
  • 594
  • 8
  • 23
0

don't unescape the + sign and add () to the end:

javascript:(function(s){try{s=document.selection.createRange().text}catch(_)  {s=document.getSelection()}prompt('State the question and answer below.','Q.' s '')})
should be
javascript:(function(s){try{s=document.selection.createRange().text}catch(_){s=document.getSelection()}prompt('State the question and answer below.','Q.'+s+'')})()
Willem
  • 5,364
  • 2
  • 23
  • 44