简体   繁体   中英

Javascript doesn't function properly once proxy is involved

I have a simple code which you can find in the following link: http://jsfiddle.net/UXCb9/26/

<form name="Form1" method="post">
<!--Form data here, irrelevant.-->
<INPUT type="button" value="Watch" onclick="return move();">
</form> 
<br><iframe name="frame1" width="50%" height="50%""></iframe>

<script type="text/javascript">  
    function move() {
        document.Form1.action = "http://translation.babylon.com/"
        document.Form1.target = "frame1";    // Open in an Iframe
        document.Form1.submit();   // Submit the page with "Form1" Data
        setTimeout("move2()", 2000);
    }
</script>
<script type="text/javascript">
    var person = { name: 'Joe Blow' };  // Disregard
    function move2() {
        document.write(person.name);  //  Write text once timer is over
    }
</script>

Basically it's just a form that once clicked calls a Java function, the function submits the form into an iframe, and finally - the user receives a short message after 2 seconds(through a timer). It works fine, but once a user tries to use the code through a "surf anonymously with proxy" website such as this: http://www.superbproxy.com/browse.php?u=http%3A%2F%2Fjsfiddle.net%2FUXCb9%2F26%2F&b=4&f=norefer

Well, it doesn't work. I've tried the code with a couple of similar proxy websites(the above is just an example) and the result is the same. I've tried figuring out why won't the proxy site process the Java properly but ran out of ideas. It's important for me that my users which use proxy (there's quite a lot) won't face any problems. Thanks in advance.

The behavior will change according to the webproxy. Some web proxies try to parse the URL's included in the Javascript code on the page however it fails when there is no semicolon at the end of the line.

You have a missing semicolon at

document.Form1.action = "http://translation.babylon.com/"

I added a semicolon and the proxies you mentioned worked fine with the jsFiddle

Demo: http://jsfiddle.net/UXCb9/28/

With Proxy: http://www.superbproxy.com/browse.php?u=http://jsfiddle.net/UXCb9/28/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM