473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

<script> tags content

42
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.
Jul 24 '07 #1
6 1515
gits
5,390 Expert Mod 4TB
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
Jul 24 '07 #2
xhunter
42
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.
Jul 24 '07 #3
gits
5,390 Expert Mod 4TB
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
Jul 25 '07 #4
xhunter
42
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_rand(), true));
$path_to_upload_script .= '?tmp_sid=' . $tmp_sid;
$path_to_ini_status_script .= '?tmp_sid=' . $tmp_sid;
[/PHP]

and the set my variables in javascript:
Expand|Select|Wrap|Line Numbers
  1.     <script language="javascript" type="text/javascript">
  2. ............ eg:
  3.     var path_to_ini_status_script = "'.$path_to_ini_status_script.'";
  4. ...........
  5.   </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.
Jul 25 '07 #5
gits
5,390 Expert Mod 4TB
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
Jul 26 '07 #6
xhunter
42
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).
Jul 27 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Madhav | last post by:
I have the following statements in my script. ---------------------------------------------------------- textToWrite = "<HTML> \n" + "<HEAD> \n" + "<TITLE>Calendar</TITLE> \n" + "<SCRIPT...
6
by: Mike Daniel | last post by:
I am attempting to use document.write(pageVar) that displays a new html page within a pop-up window and the popup is failing. Also note that pageVar is a complete HTML page containing other java...
1
by: Grzegorz ¦lusarek | last post by:
Hello everyone. I1m writing webb aplication using AJAX (prototype library: http://prototype.conio.net/ and scriptacuolous:http://script.aculo.us/). My Problem is that that I'm doing...
1
by: D. Shane Fowlkes | last post by:
I'm a fairly skilled traditional ASP/VB programmer and am learning .NET. I was (recently) surprised to read in a book about declaring and defining all my page Functions in <script...
1
by: andrew | last post by:
So I spent ages trying to work out what the problem was with my code when I did this and found a post which led me to the very simple solution. I use WebMatrix so I'm not sure if this is a major...
21
by: hemant.singh | last post by:
Hello all, I am try'g to send window.location.href to the server script who will generate dynamic javascript according to the referral name comg in as param Now bcz <script language="javascript"...
12
by: Iddo | last post by:
Hi, I am having a strange problem... I have an HTML file which has 2 script tags: 1) <script language="javascript" id="ABC" src="ABC.js" /> 2) <script id="general" language="javascript">...
44
by: rhythmace | last post by:
W3C HTML validator passes this: .... <script type="text/javascript" src="foo.js"> <script type="text/javascript"> ....script in here... </script> ....
2
by: bilaribilari | last post by:
Hi all, I am using Tidy (C) for parsing html pages. I encountered a page that has some script as follows: <script> .... var abc = "<script>some stuff here</" + "script>"; .... </script>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.