SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Extracting the image url from a string.

    Hi,

    I have a records that come from a database.

    My string, wich is "{module_webapps,5007,l,1}" returns the following:
    Code HTML4Strict:
    <a href="http://..." title="title"><img src="http://..." height="" width="" /></a>

    All I need is the actual img src url, like:

    Code HTML4Strict:
    http://...
    Is there a way to pull the image url from the string with Javascript?

    Thanks.

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,

    make the necessary changes to meet your demands, this is the basic idea

    Code JavaScript:
    var str = "<img src=\"http://...\" height=\"\" width=\"\" />";
    var patt = /^<img src=\"(.*)\" height=\"([0-9]?)\" width=\"([0-9]?)\" \/>/g;
    var result = patt.exec(str);
     
    alert(result[1]);

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks RNEL!

    What I want to achieve is a bit more complex I think...

    To put it in context, here is my source code:
    Code HTML4Strict:
    <body style="background: #010103 url({module_webapps,5007,l,1}) no-repeat fixed right top;">

    When it runs on the server the output becomes:
    Code HTML4Strict:
    <body style="background: #010103 url(<a href="linktossomewhere"><img src="/images/image.png" width="" height=""></a>) no-repeat fixed right top;">

    What I want to achieve with jQuery is:
    Code HTML4Strict:
    <body style="background: #010103 url(/images/image.png) no-repeat fixed right top;">

    Btw, I'm som what of a newbie when it comes to jQuery


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •