chanchal1987
chanchal1987

Reputation: 2367

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=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();

Computed code of the "Vtunnel" form is like below: Screenshot from Chrome

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

Upvotes: 0

Views: 415

Answers (2)

BudgieInWA
BudgieInWA

Reputation: 2255

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;

Upvotes: 1

lincolnk
lincolnk

Reputation: 11238

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... })()

Upvotes: 0

Related Questions