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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Var from inside a script inside document.write

Status
Not open for further replies.

cthood

Programmer
Mar 17, 2007
4
US
I have this code which is dynamically generated from an ad server:

document.write ('<script type="text/javascript"> var introclip =\n');
document.write ('" </script> \n');
document.write ('<img src=" border=0>');


I would like to be able to read the var introclip and use it somewhere else in my script or page. I can't seem to be able to read the variable at all though. Any thoughts?

Thanks.
 
Remove the \n in the first line of the Javascript.
Code:
document.write ('<script type="text/javascript"> var introclip = ');

Lee
 
Let's just say I can't. Then what else could I do.

The code above is being rendered automatically by the ad server. I have a URL which calls the add server and creates the above code. The introclip url is dynamically changed every time the URL is called. It's the same structure, but this portion is someone out of my control. The challenge is to be able to read the variable in this code as is. So I could do something like:

var myclip = introclip;
document.write(myclip);

 
Let's just say I can't. Then what else could I do.

Let's just say that it won't work with the \n where it is. Look at what the code actually creates (double line breaks added for clarity):

Code:
<script type="text/javascript"> var introclip =

"[URL unfurl="true"]http://oascentral.domain.com/RealMedia/ads/adstream_lx.ads/domain.com/domain/home.do/2013086587/Frame1/domain/co/4151461/34316665653032353435666332393430";[/URL] </script>

<img src="[URL unfurl="true"]http://bbeplayer.com/Tracking/V3/Instream/Impression/?0|528|4348|2044|513|869|http%3A//ad.doubleclick.net/ad/N2870.CoCo/B1847568.21%3Bsz%3D1x1%3Bord%3D%5Btimestamp%5D%3F|BBEEND|"[/URL] border=0>

As well, the </script> inside the quotes will terminate the Javascript early, causing other problems. You'll have to break that up into something like

Code:
'</scri' + 'pt>'

If you want to use THAT code from the ad server, I'd recommend writing it to the page with server-side scripting rather than client-side.

Lee
 
Ok, I do understand your point, but what I'm confused about is that the script I posted is being used today.

The ad server generates the code above.
The URL refers to an Flash Video (FLV) file.
We have a SWF/FLV Player on the site which reads the code.
The Code is parsed out one way or another to get the URL identified by the introclip var.
The SWF/FLV player then plays the video clip which the ad server scheduled.

In short it's being done today through some process, I'm just trying to determine if I can duplicate it through Javascript.

Thanks for your feedback.
 
I ended up using PHP to parse out the url I needed. It's much easier this way.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top