我正在尝试为http://www.vtunnel.com/创建一个“复制-粘贴javascript”(当用户将这个javascript粘贴到url栏并按回车键时,它就会起作用)。我的脚本会自动创建一个表单到当前页面,值的"textbox“会自动填满当前的url,并提交表单。我正在尝试这个JavaScript:
javascript:
_vtunnel_form=document.createElement('FORM');
_vtunnel_form.name='login';
_vtunnel_form.method='POST';
_vtunnel_form.action='http://www.vtunnel.com/index.php';
_vtunnel_h1=document.createElement('INPUT');
_vtunnel_h1.type='TEXT';
_vtunnel_h1.name='username';
_vtunnel_h1.value=encodeURIComponent(location.href);
_vtunnel_form.appendChild(_vtunnel_h1);
_vtunnel_h2=document.createElement('INPUT');
_vtunnel_h2.type='HIDDEN';
_vtunnel_h2.name='r4';
_vtunnel_h2.value=' checked';
_vtunnel_form.appendChild(_vtunnel_h2);
_vtunnel_h3=document.createElement('INPUT');
_vtunnel_h3.type='HIDDEN';
_vtunnel_h3.name='fa';
_vtunnel_form.appendChild(_vtunnel_h3);
_vtunnel_h4=document.createElement('INPUT');
_vtunnel_h4.type='HIDDEN';
_vtunnel_h4.name='if';
_vtunnel_h4.value=' checked';
_vtunnel_form.appendChild(_vtunnel_h4);
document.body.appendChild(_vtunnel_form);
_vtunnel_form.submit();“V隧道”表单的计算代码如下所示:

但它不能正常工作。它给出了一个404错误。为什么?有什么解决方案吗?
发布于 2010-10-22 05:03:05
据我所知,表单将被提交给http://www.vtunnel.com/index.php,它会给出404错误。动作URL是你的屏幕截图和我的截图是一样的,所以把你脚本的第五行改成这样应该行得通:
_vtunnel_form.action='http://www.vtunnel.com/index.php/1010110A/ee908e12b7cb248c8ffd5b100619688';编辑:因为这仍然会把你带到404,所以仍然有一个问题。事实证明URL不应该是URI编码的。删除encodeURIComponent函数,使代码行如下所示:
_vtunnel_h1.value=location.href;发布于 2010-10-22 04:55:05
你确定你的脚本运行正常吗?我通常最终会将所有内容包装在一个自调用函数中,以使其正常工作。
javascript:(function() { ...everything there... })()https://stackoverflow.com/questions/3991779
复制相似问题