<script> tags content

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xhunter
    New Member
    • May 2007
    • 42

    <script> tags content

    Hi,

    I am loading a page using ajax,

    I want to match the content of <script>***</script> tags, and use eval() to evaluate them instead,

    I tried alot but I couldn't find a proper pattern for a regular expression to be used for this purpose.
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    you may simply use the innerHTML-property of the script-node ;)

    but why do you want to go that (ugly) way? ... there is usally only one thing for what eval is good for: evaluating a json-string to an js-object! you simply may call the function in the onload-handler of the page ... and don't need the eval here.

    kind regards

    Comment

    • xhunter
      New Member
      • May 2007
      • 42

      #3
      I am not sure how that is possible,

      I would be loading variety of pages, and wouldn't always have access to the source of the loading page,

      so it would be easier if I just find the scripts and have their functions available for later user.

      specially if those javascript tags contain some values that eg has a "sid" number (a random number) created lets say be php, which makes it necessary that I would evaluate the javascript that is in the response which already has these values set specifically for that response .

      otherwise I was also thinking if I had full access to the page, use the php to extract all the tags and and load them as script before loading the actual page, which is even more uglier.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        hi ...

        may be i don't really get it ... but in onload of the page (every page) you (must) have! access to the source ... since it is loaded to the client and you may retrieve everything that is written or even generated by the server? ... could you give an example of the problem?

        kind regards

        Comment

        • xhunter
          New Member
          • May 2007
          • 42

          #5
          ok here is an exampl,

          it is my upload script, a combination of php and javascript,

          first I add a sid value through php (which I will use it later for identification) :
          [PHP]
          $tmp_sid = md5(uniqid(mt_r and(), true));
          $path_to_upload _script .= '?tmp_sid=' . $tmp_sid;
          $path_to_ini_st atus_script .= '?tmp_sid=' . $tmp_sid;
          [/PHP]

          and the set my variables in javascript:
          Code:
              <script language="javascript" type="text/javascript">
          ............ eg:
              var path_to_ini_status_script = "'.$path_to_ini_status_script.'";
          ...........
            </script>
          and then when I submit the form, the values are used for the process.

          so I don't want to load anything, just to have the variable that I set available.

          similarly, if lets say that script was only a function which is to do something based on users input,


          I just need to find all these already set variables and functions in the response text and have them available in the page where they were loaded to.

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            hmmm ...

            but the php-code is executed at the server and the js-variable already has the value assigned you set during the php-execution ... so when you are at the client you simply need to get that value ... you won't need the eval for that ... or am i wrong with that? ...

            kind regards

            Comment

            • xhunter
              New Member
              • May 2007
              • 42

              #7
              that's the problem, the value being assigned in javascript is based on what was created in php on the server side, which will change on every page load (which is also sent to my upload script to identify different uploads)

              so if I open "test.php" directly, I will have the value assigned correctly, but if I load it with ajax, even though the value is set their but ofcourse as it was not evaluated by the broswer, it is like that value was never set.

              and there is not much another way to set that value again other than making the browser to evaluate the loaded javascript.


              so basically I am talking about unique values that can not be recreated outside the main script (test.php).

              Comment

              Working...