SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2002
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    parsing javascript?

    hi

    i have a js that displays certain content. However, on my main page, i only want to display one or two sections of the content(ie. only a few parts of the js file)

    How would i go about parsing the js file?
    Myasia.ca - now launched! Please test, and try some programs - support me

  2. #2
    SitePoint Addict Caterwomtious's Avatar
    Join Date
    Dec 2001
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use a variable as a flag, and alter the original file to be dependent on if statements.

    For example, if your existing js file is:

    Code:
    document.write("first bit of content");
    document.write("second bit of content");
    and you want always to show the first bit of content, but only want to show the second on specific pages, change it to:

    Code:
    if (showExtra != false) showExtra = true;
    
    document.write("first bit of content");
    if (showExtra) document.write("second bit of content");
    The magic is in the first line, which ensures that showExtra is set to true unless it is set explicitly to false.

    With this done, to show all the content just include the js file - you can leave your existing HTML files unaltered. But to have the pared-down version for your home page, insert the following line of Javascript before you include the js file:

    Code:
    var showExtra = false;

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2002
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but i was wondering if there was a solution where it could be parsed without actually touching the js file?
    mb with xml>?


    can anyone please help me?
    Myasia.ca - now launched! Please test, and try some programs - support me

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2002
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cmon please....can someone please help me-

    a solution where the external js file is not touched

    thanks
    Myasia.ca - now launched! Please test, and try some programs - support me

  5. #5
    SitePoint Addict Caterwomtious's Avatar
    Join Date
    Dec 2001
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Not on the client, you don't

    Is the original js file completely off-limits? As far as I know you can't do what you want on the client-side - you'll need server-side scripting using PHP, ASP, ColdFusion or similar. If you have one of those available, perhaps you should try asking again in the relevant forum.

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    BOSTON
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm....
    just to say this out so it can be verified if it does or does not make sense...
    REQUIREMENT:
    you want to a parse a file that cannot be touched

    this file, is to dictate a document.write or it is to actually implement a document write,.. meaning are you going to execute the code or execute something else based on what is there?
    I am going to assume execute the code...
    (which REALLY makes me wonder why you won't touch it!)

    if you aren't going to touch it, then you must have a pre or post kind of processor that detects the execution and filters out the content you want,
    to go in the same direction using xml... you could do several things, but one way or another you are going to have to implement something that either produces a separate js file for the execution, or changes the existing one,.. and if it we are talking xml transformation than we need more info and more than likely it must have some kind of server sideness to it

    toss some attributes of this requirement our way and lets see if we can better define what the background options are
    i'm done with stuff at work!
    reply!
    PEACE

  7. #7
    SitePoint Zealot
    Join Date
    Jan 2002
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi thanks for the reply..

    --
    as to what i need, i'll try to make it clearer:

    there is a js that displays the data required. It has a lot of document.write to show the content.

    I am using the file on one of my secondary pages. However, i want to use it on my main page.

    On the main page, tho, I only want to display TWO of the document writes. so, in a sense, only a FEW lines of that code will be touched.

    I can't touch the js file in any way.

    I am pretty sure that it is possible-as all i think it is is parsing. I can use any solution possible(xml, rss, etc.)..
    --
    I hope that clears that up. Please help
    Myasia.ca - now launched! Please test, and try some programs - support me

  8. #8
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by myasia
    hi thanks for the reply..

    --
    as to what i need, i'll try to make it clearer:

    there is a js that displays the data required. It has a lot of document.write to show the content.

    I am using the file on one of my secondary pages. However, i want to use it on my main page.

    On the main page, tho, I only want to display TWO of the document writes. so, in a sense, only a FEW lines of that code will be touched.

    I can't touch the js file in any way.

    I am pretty sure that it is possible-as all i think it is is parsing. I can use any solution possible(xml, rss, etc.)..
    --
    I hope that clears that up. Please help
    The only way to do this would be to open a new window and write exactly what you want into that window. Javascript has no way to parse itself. So in theory or pseudo code this is what you would do

    user logs on
    page opens up
    the page open popup
    page one writes only what is specified on page 2
    page one closes
    this leaves a parsed page

    However. this ends up popping a prompt to close the first page. A way around this is something simple.

    use logs on
    pages opens up, popping up a replica of itself and moving over focus
    page 2 writes to page 1 what you want done
    page 2 closes
    this leaves a pseudo parsed page

    The only way to truly parse would be to use a server sided language.

    I may have your explanation way off but that essentially simulates parsing in a really really ugly way.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  9. #9
    SitePoint Zealot
    Join Date
    Jan 2002
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    which server-soide language? also please give me your idea--i'm willing to try anyhitng!!!

    Myasia.ca - now launched! Please test, and try some programs - support me

  10. #10
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by myasia
    which server-soide language? also please give me your idea--i'm willing to try anyhitng!!!

    Well your best bet belonging to these forums would be php. The help here is top notch and always ready. IT is also one of the easiest to learn especially for the basics. Try asking in the php forum for help about parsing your files.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.


Bookmarks

Posting Permissions

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