www.webdeveloper.com
Results 1 to 5 of 5

Thread: A syntax help required

  1. #1
    Join Date
    May 2012
    Posts
    39

    A syntax help required

    Hi ,

    In my javascript function I am trying to redirect to a page which takes an argument and that argument itself is a url. Hence the entire thing getting mesed up. Please help me how can I pass the url so that it treats it as a argument .

    My code is below :



    Code:
    function createfile ()
    {
    
    var currenturl = document.URL;
    var link = "http://report.systems.com/cgi-bin/mainscript.pl?url="+currenturl;
    
    window.location.href = link ;
    
    }

    FYI, the currenturl here is also an url of following type :
    "http://report.systems.com/cgi-bin/monitor.pl?path=/usr/test;"

    Please also tell me how can I pass two variables as parameters to a redirection statement , for example , likewise above 'url' argument and its value 'currenturl' , if I also want to pass an argument say 'filter' and its value as a javascript variable 'val' .

    Let me clarify , how can I write the following function to pass both url and filter :

    Code:
    function creatfile ()
    {
    var currenturl = document.URL;
    var val = "yes";
    var link = "http://report.systems.com/cgi-bin/mainscript.pl?url="+currenturl"?filter="+val;
    
    window.location.href = link ;
    
    }
    thanks.

  2. #2
    Join Date
    Jul 2013
    Posts
    66
    This question has been answered in detail in another forum.

  3. #3
    Join Date
    Jun 2008
    Posts
    106
    Please learn how to use JavaScript before trying to use it. And always use your error console.

    Code:
    function creatfile() {
        var val = "yes";
        window.location.href = "http://report.systems.com/cgi-bin/mainscript.pl?url=" + escape(document.URL) + "&filter=" + escape(val);
    }

  4. #4
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,277
    For this use, encodeURIComponent would be better as escape.

  5. #5
    Join Date
    Jun 2008
    Posts
    106
    Quote Originally Posted by 007Julien View Post
    For this use, encodeURIComponent would be better as escape.
    Yeah, true.



    Code:
    function creatfile() {
        var val = "yes";
        window.location.href = "http://report.systems.com/cgi-bin/mainscript.pl?url=" + encodeURIComponent(document.URL) + "&filter=" + encodeURIComponent(val);
    }

    Btw... can we not edit our posts on this forum?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles