Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing a javascript

Status
Not open for further replies.

Deleted

Technical User
Jul 17, 2003
470
US
Need to remove the javascripts from the html example below and assign them (javascript's) to a variable to be processed later on.

Thanks in advance..

[EXAMPLE]

<html>
<head>
<title>test</title>

<script language="javascript">
alert('welcome');
</script>

<script language="javascript">
document.write('hello');
</script>

</head>
<body color="000000">

blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah

</body>
</html>

M. Brooks
X Concepts LLC
 
Just to give you a heads up..

my $variable = qq|

<html>
<head>
<title>test</title>

<script language="javascript">
alert('welcome');
</script>

<script language="javascript">
document.write('hello');
</script>

</head>
<body color="000000">

blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah

</body>
</html>

|;

M. Brooks
X Concepts LLC
 
to a variable to be processed later on"

i interpreted this to mean:

my $scrip1= .....

......
</script>
........

later
print "onSubmit=$scrip1 ...... "

is this corecct?
 
Basically I want to extract the javascript's from a string and assign the data to a variable (ex: $grabbed_scripts).




M. Brooks
X Concepts LLC
 
This is what I came up with. It works on scripts written like

<script language="javascript">alert('welcome');</script>

but not on

<script language="javascript">
alert('welcome');
</script>

my @js_data = $variable =~ /<script.*>(.*)<\/script>/gi;
print "@js_data";
exit;

Any suggestions?

M. Brooks
X Concepts LLC
 
now i interpret what you want is to capture the contents between the <script ..> and </script> ??

if so:

$variable =~ s/<.*?>//g; # leaves empty lines.

why not capture full script (with the <>'s)?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top