url decode - 不起作用

时间:2013-03-22 11:24:22

标签: javascript urlencode bookmarklet urldecode

为什么以下解码的脚本不起作用?原始代码似乎运行得很好。

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

原始代码:

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

非常感谢。

2 个答案:

答案 0 :(得分:1)

它将+符号解码为空格,试试这个:

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

区别:将' s '更改为此'+s+'

答案 1 :(得分:0)

不要取消+符号并添加()到最后:

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+'')})()