开发者

Problem while creating "copy-paste JavaScript"

I am trying to create a "copy-paste javascript" (it will work when user paste this javascript on the url bar and press the return key) for http://www.vtunnel.com/. My script will automatically create a form to the current page and value of the "textbox" will automatically filled up with the current url, and submit the form. I am trying this 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=docu开发者_Go百科ment.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();

Computed code of the "Vtunnel" form is like below:

Problem while creating "copy-paste JavaScript"

But it is not working properly. It is giving a 404 error. Why? Are there any solution?


As far as I can tell, the form will be submitted to http://www.vtunnel.com/index.php which gives the 404 error. The action URL is your screenshot is the same as mine, so changing the fifth line of your script to this should work:

_vtunnel_form.action='http://www.vtunnel.com/index.php/1010110A/ee908e12b7cb248c8ffd5b100619688';

EDIT: Because that still leads you to a 404 there's still a problem. It turns out the URL shouldn't be URI encoded. Remove the encodeURIComponent function so the line looks like this:

_vtunnel_h1.value=location.href;


are you sure your script is running properly? I usually end up wrapping everything in a self-invoking function to make it work.

javascript:(function() {  ...everything there... })()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜