Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    please help me in java script

    I have 2 files one is results.html and second is js_script.js when i put both of files in same directory thay work well but when i put js_script.js in another directory thay don't work. I even changed directory location in results.html but is don't work. Please help me where should i edit my code?

    here is

    results.html
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">

    <html>
    <head>
    <title>JSE SEARCH RESULTS</title>

    <script language="JavaScript1.3" type="text/javascript" src="js_script.js"></script>

    </head>

    <body>

    <form name="jse_Form" onsubmit="search_form(jse_Form);return false">
    <input type="text" name="d">
    <input type="button" value="Go" onClick="search_form(jse_Form);">
    </form>

    <script language="JavaScript1.3" type="text/javascript">return query();</script>

    <script language="JavaScript1.3" type="text/javascript">num_jse();</script> Results found
    <hr>
    <p>
    <script language="JavaScript1.3" type="text/javascript">
    out_jse();
    </script>

    </body>


    </html>
    and here is
    js_script.js
    // ---------- script properties ----------


    var results_location = "";


    // ---------- end of script properties ----------


    function search_form(jse_Form) {
    if (jse_Form.d.value.length > 0) {
    document.cookie = "d=" + escape(jse_Form.d.value);
    window.location = results_location;
    }
    }

    // ---------- script properties ----------

    var include_num = 1;
    var bold = 0;

    // ---------- sites ----------


    var s =["^^fair^","^^fairly^","^^fairness^"];



    // ---------- end of script properties and sites ----------





    var cookies = document.cookie;
    var p = cookies.indexOf("d=");

    if (p != -1) {
    var st = p + 2;
    var en = cookies.indexOf(";", st);
    if (en == -1) {
    en = cookies.length;
    }
    var d = cookies.substring(st, en);
    d = unescape(d);
    }
    var od = d;
    var m = 0;
    if (d.charAt(0) == '"' && d.charAt(d.length - 1) == '"') {
    m = 1;
    }

    var r = new Array();
    var co = 0;

    if (m == 0) {
    var woin = new Array();
    var w = d.split(" ");
    for (var a = 0; a < w.length; a++) {
    woin[a] = 0;
    if (w[a].charAt(0) == '-') {
    woin[a] = 1;
    }
    }
    for (var a = 0; a < w.length; a++) {
    w[a] = w[a].replace(/^\-|^\+/gi, "");
    }
    a = 0;
    for (var c = 0; c < s.length; c++) {
    pa = 0;
    nh = 0;
    for (var i = 0; i < woin.length; i++) {
    if (woin[i] == 0) {
    nh++;
    var pat = new RegExp(w[i], "i");
    var rn = s[c].search(pat);
    if (rn >= 0) {
    pa++;
    } else {
    pa = 0;
    }
    }
    if (woin[i] == 1) {
    var pat = new RegExp(w[i], "i");
    var rn = s[c].search(pat);
    if (rn >= 0) {
    pa = 0;
    }
    }
    }
    if (pa == nh) {
    r[a] = s[c];
    a++;
    }
    }
    co = a;
    }

    if (m == 1) {
    d = d.replace(/"/gi, "");
    var a = 0;
    var pat = new RegExp(d, "i");
    for (var c = 0; c < s.length; c++) {
    var rn = s[c].search(pat);
    if (rn >= 0) {
    r[a] = s[c];
    a++;
    }
    }
    co = a;

    }


    function return_query() {
    document.jse_Form.d.value = od;
    }

    function num_jse() {
    document.write(co);
    }

    function out_jse() {
    if (co == 0) {
    document.write('No Result Found! Please Try Again With Difrent KeyWord');
    return;
    }
    for (var a = 0; a < r.length; a++) {
    var os = r[a].split("^");
    if (bold == 1 && m == 1) {
    var br = "<b>" + d + "</b>";
    os[2] = os[2].replace(pat, br);
    }
    if (include_num == 1) {
    document.write(a + 1,'. <font size="4', os[1], '">', os[0], '</a>', os[2], '</font><p>');
    } else {
    document.write('<a href="', os[1], '">', os[0], '</a><br>', os[2], '<p>');
    }
    }

    }


  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by Shairy_fairy View Post
    I have 2 files one is results.html and second is js_script.js when i put both of files in same directory thay work well but when i put js_script.js in another directory thay don't work.
    The only explanation is that the path to your directory is not correctly specified. Or conceivably that the directory permission list is incorrectly set (chmod).

    It is your responsibility to die() if necessary….. - PHP Manual
    Last edited by Philip M; 04-17-2013 at 08:00 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i specified so many time the path of the directory for example results.html in directory E:\new folder\results.html and D:\new folder\js_script.js but it doesn't work can you give me correct code by checking these file on your computer.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by Shairy_fairy View Post
    i specified so many time the path of the directory for example results.html in directory E:\new folder\results.html and D:\new folder\js_script.js but it doesn't work can you give me correct code by checking these file on your computer.
    Are you saying that the files do not work locally? Are you sure that the directories exist?
    Last edited by Philip M; 04-17-2013 at 08:18 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I checked in every way as you say case sensitivity. directories are exist in my computer if as well as when i put whole code in one page it works pretty well. but i want to put my js_script file on an another server as well but it doesn't work i will be very much thank full to you if you would like to help me

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by Shairy_fairy View Post
    but i want to put my js_script file on an another server as well but it doesn't work
    Well, no. It will not work if the file is on another server. You said another directory.

    For security reasons JavaScript cannot access anything beyond the domain of the current page. This is known as the "same origin policy" and prevents a document or script loaded from one origin from getting or setting properties of a document from a different origin.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #7
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by Philip M View Post
    Well, no. It will not work if the file is on another server. You said another directory.

    For security reasons JavaScript cannot access anything beyond the domain of the current page. This is known as the "same origin policy" and prevents a document or script loaded from one origin from getting or setting properties of a document from a different origin.
    BS, <script src> tags (and images and stylesheets and video and audio) can come from anywhere.
    how the heck would google CDN copies of jQuery get so much use if only html from the CDN could use it?

    The only exception/limitation is the dreaded "mixed content" warning in IE if you load a script from http while on a page that's https. If they are both the same protocol, it should work.

    IE's local-resource limitations MIGHT block LOCAL resources to non-origin sources, but that's not the same thing as the SOP.

    OP: you can save the .html file are .hta to get around this, or put your js on the web and point to it at an http url instead of a file path.
    you really should be using a local HTTP server to develop, but that's another topic...
    Last edited by rnd me; 04-17-2013 at 08:04 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #8
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i am creating a blogger page and tried my html file on blogspot and sentenses.js file is on this server .i saw so many people using external java scripts on blogspot i even did so many time before but all of this making me more disappointed.can you check now what is the real problem is? and plz post me correct solution if you would like to plz brfore answering me test it first on your system by putting all of this in different directories or server so that you can easily understand what i am saying about, if thay work then plz reply me if dont work then plz give me the right sollution.
    thanks.

    <script type="text/javascript" src="http://yourjavascript.com/6132848412/js-script.js"></script>

  • #9
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by Shairy_fairy View Post
    i am creating a blogger page and tried my html file on blogspot and sentenses.js file is on this server .i saw so many people using external java scripts on blogspot i even did so many time before but all of this making me more disappointed.can you check now what is the real problem is? and plz post me correct solution if you would like to plz brfore answering me test it first on your system by putting all of this in different directories or server so that you can easily understand what i am saying about, if thay work then plz reply me if dont work then plz give me the right sollution.
    thanks.
    if both the page and the script urls start with http, it will work.
    you cannot link from blogger to a folder on your computer.
    yoyu can link from blogger to any other http-based script file, as you know.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #10
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i tried by uploading both files on different servers both files url starts with http
    but i even then didn't find the solution, now i don't want to west more time of any one i would like thanks to you for giving me your valuable time.
    thanks


  •  

    Posting Permissions

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