[Javascript] Selecting certain areas of text in a string

Nick Fitzsimons nick at nickfitz.co.uk
Tue Mar 10 12:30:19 CDT 2009


Apologies if this gets posted twice - my webmail is playing up :-(

Assuming your <object> element has the ID "movie" then

var movie = document.getElementById("movie");
movie.src = movie.src.replace(/somevideo.flv/, "othervideo.flv");

should do the trick.

Regards,

Nick.

On Tue, March 10, 2009 3:35 pm, javascript at webdesignofficina.com wrote:
>
> Hi there,
>
> Currently trying to change the url of an embedded element in a page...
> My problem is that many other parameters are passed along the url of
> the object, in the src property:
>
> src="../pluginsv/mediaplayer.swf?file=http://www.somesite.com/video/
> somevideo.flv&autostart=true&displayheight=202&allowfullscreen=over&controlbar=over&usefullscreen=true&backcolor=0x121212&frontcolor=0xffffff&lightcolor=0x000000&bufferlength=10"
>
> I'd like to only rewrite this part: file=http://www.somesite.com/
> video/somevideo.flv
> Rest of the parameters should remain untouched...
>
> I know I should use String.replace, something like:
>
> var str="somevideo.flv!";
> document.write(str.replace(/somevideo.flv/,"othervideo.flv"));
>
> But I have absolutely no idea on how target this piece of text only in the
> whole src="...", starting from ending file path, from / to .flv
>
> Any help would be greatly appreciated.
>
> Thank you.
>
> Best regards,
>
> Guillaume Stricher
> _______________________________________________
> Javascript mailing list
> Javascript at lists.evolt.org
> http://lists.evolt.org/mailman/listinfo/javascript
>


-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/





More information about the Javascript mailing list