iframe - Replace part of a url with jquery | Soundcloud player -


i want replace "visual=true" "visual=false" in each link starts "https://w.soundcloud.com/player/?url=". possible? want force embedded soundcloud players in blog change style (example:http://jsfiddle.net/grey2/).

<iframe width="100%" height="450" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3a//api.soundcloud.com/tracks/84808541&amp;auto_play=false&amp;hide_related=false&amp;visual=true"></iframe> 

is there way jquery?

you can use txt.replace('search', 'replace') perform string replace , txt.indexof('search') find if string contains pattern search for.

this code should work you:

$("iframe").each(function() {     var src = $(this).attr('src');     if(src.indexof('https://w.soundcloud.com/player/?url=') != -1 && src.indexof('visual=true') != -1) {         $(this).attr('src', src.replace('visual=true', 'visual=false'));     } }); 

because assigning new src reloads iframe, hence creating http request i've added additional check if action should performed && src.indexof('visual=true') != -1. replaces src whenever it's needed leaving other iframes untouched.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -