javascript - Changing an image source based on an H1 element in the source code or 'location.path'? -


I decided to try a different approach to this problem instead of depending on the string I thought this specific issue To use the function location.path , the album will be more efficient to determine the source of the cover. Even I still have a lot of things:

HTML snippet for the image:

  & lt; Img src = "http://static.last.fm/flatness/catalogue/noimage/noalbum_g3.png" width = "220" height = "220" square = "album-cover" /> I have a piece of javascript:  
  var albumCover = document.getElementsByClassName (album-cover) // Album cover var currentLink = Location. Pathname var dictionary = {// location.pathname: image source for albumCover '/ music / King + Crimson / Red': 'http://i1325.photobucket.com/albums/u622/last_fm_projeKct/Last%20FM%20covers/ RED.JPG ',' / Music / King + Crimson / Discipline ':' http://i1325.photobucket.com/albums/u622/last_fm_projeKct/Last%20FM%20covers/Discipline.jpg '}   Now it is a piece of code that is incomplete:  
  if (currentLink === "// part of the dictionary") {albumCover.src = '' second dictionary Part;}; other{};   

Any help is welcome and reading, thanks for the cheers.

Older Posts: I have a follow up on a recent question but I can not seem to be able to change the code for what I'm seeing. The code is on the following website:

I am interested in changing the image source in the code below. However, the new image source has to be determined based on the H-1 element of that webpage.

  & lt; Div class = "g3 album-cover-wrapper album-cover-wrapper-no-cover" & gt; & Lt; Img src = "http://static.last.fm/flatness/catalogue/noimage/noalbum_g3.png" width = "220" height = "220" square = "album-wrapper" /> & Lt; Section square = "Remove add-top-margin-down-margin" & gt; & Lt; Div class = "g4" & gt; & Lt; / Div & gt; & Lt; / Section & gt; & Lt; / Div & gt;   

Now I thought it would be useful to use the 'Dictionary List' like the following:

  If the string in H1 is 'discipline' { Img.src = "Newsource.jpg '}}   

Thanks for taking the time to read this, Cheers!

EDIT: Here is a piece of code What I was trying to do but I guess it requires more information to actually work.

HeaderDef = document.getElementsByTagName ('h1'), var img = Document.getElementsByClassName ('album-cover'); if (headerdif === 'red') {img.src = "newsource.jpg";}; else {};

Some examples of this list are: // String in H1: Image of 'album-cover' category New picture source for 'discipline': 'http: //ecx.images- Amazon.com/images/I/41kcnkbxS-L._SL500_AA300_.jpg ',' Red ':' http://img.noiset.com/images/album/king-crimson-red-4-cd-cover-31985 Gif ', etc ...

This is a list for which I must manually add each instance of a specific H-1 string page.

I give the following suggestions:

  var map = {' Lal ':' O my god! ',' Blue ':' blue? Actually..?' }; Function effect image (source, map) {if (Source!! Map) {return false; } And {var text = source.textContent || Source.innerText; (Different words in the map) {if (map.hasOwnProperty (word) & text.indexOf (word)! == -1) {return map [word]; }}}} // In real life, with an image use: // imageNode.src = effect image (document.getElementsByTagName ('h1') [0], map); Document.getElementById ('test'). Title = effect image (document.getElementsByTagName ('h1') [0], map); One ????   

. In the demo I set the a element of a a element, but, exactly, as mentioned in the comment, only one image node has src attribute.

The above change, in a little ( else {...}

  Var text = (source.textContent || source.innerText) .toLowerCase (); (Var word in map) {if (Map.hasOwnProperty (word) & amp; text.indexOf (word.toLowerCase ())! == -1) Map of return [word];}}   

.

Any other edits, again to add a default option, within else {...} if there is no word match:

  Var text = (source.textContent || source.innerText) .toLowerCase (); (Different words in the map) {if (map.hasOwnProperty (word) & text.indexOf (word.toLowerCase ())! == -1) {return map [word];}} // We only here See if `for` loop and` if` do not throws a match. Return 'Default String';   

.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -