Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

HTML & CSS Open a webpage from an XML array

thesoundsmith

Active Coder
Hi, folks. first time poster, sorry if I screw up the layout.
I have a WordPress site which began as HTML/CSS. www.davidkempton.com, formerly www.thesoundsmith.com since 1998
I have not done any significant work on the site since 2010, so I have forgotten javascript and a lot of html.

The site has a couple hundred audio files connected to 20 separate pages .
I use "jwplayer" on a page from the original HTML site, here's their reference link Playlist
I could NOT get the GUI to translate to WordPress, so it is not in their list of pages or posts. When you click the link on the menu bar, it opens as a separate window.

Everything works great except for one feature. If you like the song and want to download it, I want one button to send you to the proper page. The address is stored in the XML file item as a site address in the field 'link' Examples:

<link>Life Cycles | The Soundsmith</link>
<link>Primary Trigrams of the I Ching | The Soundsmith</link>
<link>After The Fall | The Soundsmith</link>

The command that almost words is this: (I hit Inline Code but nothing happened, sorry)
<li><a id="btn1" class="button3" title="Download This Song" <a href="(jwplayer(radio).getPlaylistItem().link);" target="blank">D/L</a> </li>

HTML:
<!-- The command that almost words is this: -->
<li><a id="btn1" class="button3" title="Download This Song" <a href="(jwplayer(radio).getPlaylistItem().link);" target="blank">D/L</a> </li>

another option that I thought worked  is this:
<li><a id="btn1" class="button3" title="Download This Song" onclick="window.open(deCod(jwplayer(radio).getPlaylistItem().link));">D/L</a></li>
that call is to:
function deCod(linkStr)  {
var str=linkStr;
return str;
}

<!-- I have tried <a href="deCod(jwplayer(radio).getPlaylistItem().link);" target="blank"> with no luck

other commands that DO work include
<li><a id="btn4" class="button3" title="Play/Pause" onclick="jwplayer(radio).play('false');">Pause</a></li>
<li><a id="btn5" class="button3" title="New Song" onclick="jwplayer(radio).playlistNext();">New</a></li>
<li><a id="btn6"  title="Close DashRadio" onclick="window.open('', '_self', '');window.close();"></a></li>  -->
This has two problems - it has worked a couple times when first reloaded and it DOES open the correct page. But then reverts to the error Can't find https://www.davidkempton.com/(jwplayer(radio).getPlaylistItem().link (radio).getPlaylistItem().link)
or sometimes Can;t Find ! TheSoundsmith. That's the MAIN problem The call to getPlaylistItem().link should return the web address as an http:// to open, and does not.
the other issue is that i would like the call to open in the parent window instead of a new tab/window.. I tried variations of target="parent" but got a blank result instead of the error page. BTW I have tried versions of onclick() as well, at least the Anchor opes a window.
I have run the XML files past the validator as well.

Help please. I only do this about every five years and forget EVERYTHING in between... Thanks for what you can offer.
 
Solution
Thanks for your help. I'm not going to worry about the parent problem, This solution does what I need, and I have actual music to make. If someone wants to download a track, they can deal with a second window. Let's consider this closed, and thanks again.
Yeah, makes sense. Making music is more important than changing websites. Please make sure to close the case by marking one of the comments (even if it's your own) as the solution.
One thing I see right away is you have "a" inside an "a":

<li><a id="btn1" class="button3" title="Download This Song" <a href="(jwplayer(radio).getPlaylistItem().link);" target="blank">D/L</a> </li>

should be:

<li><a id="btn1" class="button3" title="Download This Song" href="(jwplayer(radio).getPlaylistItem().link);" target="blank">D/L</a> </li>

Hope that helps.
 
Thanks for the help.

// using this: <li><a id="btn1" class="button3" title="Download This Song" href="(jwplayer(radio).getPlaylistItem().link);" target="blank">D/L</a> </li>

I'm getting responses like this Page Not Found :error page link

Changing to add the "deCod" function which I understand to return a string from whatever field parameter you send it, it's above,
// <li><a id="btn1" class="button3" title="Download This Song" href="deCod(jwplayer(radio).getPlaylistItem().link);" target="blank">D/L</a> </li>
This still returns:the same Page not found error.

The return shows the site address David Kempton's The Soundsmith, so even if it did return a string it would fal. What I want is to open the page that relates to the song currently playing. (IF I get that close there are two URL paths,, I can remove that part of the URL from the XML files, but I'd rather avoid that. I have tried variations of this with the parens in the href, with a set around the deCod to the end of 'link; etc. Main issue - I cannot get the CONTENT of the 'link' field from the XML file, example in the post above. If I get that, I should be able to work the rest out.

Thanks again.
 
That s a nice looking site you have. I'd be happy to try and help but I have to confess that your problem description is quite unclear to me. If you just tell me what to click to reproduce the problem(s) that might help.
 
Thanks for the reply, the site has been evolving since 1998, WordPress since 2008. so some code is ancient.

This page of the site is independent of the main WordPress site. When I updated for my old HTML/CSS site, I could not make this work in their universe, so i just linked to it in a menu. There a couple hundred MP3 files of my music, "DashRadio" plays them from a set of XLM lists, which are selected by the top row buttons. The lower row lets you Play, Pause or select a New random song from the list.

Originally, the "D/L" button was lhard-code inked to a catalog page to purchase a given MP3, but the store is closed, so the purpose of the button marked "D/L" now is to open the page from the main site where this song is found. The music player on that page will let the user download what he wishes.

The URL of the page is in the XML file under the name "Link" so I want to click "D/L" and have it open the page referenced. And if possible, to open it on the already-opened copy, not a new one, though I'll be OK if it is a new page. Parent() did not seem to help, perhaps because it's not part of the WP universe?

What I get is shown in the post above. Anything you can do to help is greatly appreciated.
 
That is a lot of text again, mostly going right over my head - and in my opinion of little relevance to the specific problem. When describing an IT problem, never give more information than is needed to understand the problem. It will only confuse the poor support engineer 😉

Just tell me the exact steps to reproduce the problem on your site, then I will give it a shot. But knowing zilch about WordPress, I may well be powerless to help.
 
Open the site at David Kempton's The Soundsmith
Click on the last Menu item, "DashRadio"
Click on the button marked "New", to start a new song playing. Let it load, then...
I don't see any button marked "New" 🤔 A song already starts playing automatically after a second or so.

Click "D/L". This generates an error instead of a working link to the page.
There is indeed a D/L button, underneath the "Easy" button. Clicking it produces this screen:

a.jpg

Is this the problem you are describing ? Just taking it one small step at a time here...
 
I think I know what the problem is here. Your D/L button has this HTML code

<a id="btn1" class="button3" title="Download This Song" href="deCod(jwplayer(radio).getPlaylistItem().link);" target="blank">D/L</a>

which should be

<a id="btn1" class="button3" title="Download This Song" href="javascript:deCod(jwplayer(radio).getPlaylistItem().link);" target="blank">D/L</a>

Note the added javascript: in the href. Without that, it will try to load a HTML page of that name, which obviously fails.
 
Thanks greatly for your help. I just a moment ago found the solution - I went to the Wayback Machine and retrieved a functioning page from 2018 - to my surprise, the line worked perfectly:
<li><a id="btn1" class="button3" title="Download This Song" onclick="window.open(deCod(jwplayer(radio).getPlaylistItem().link));">D/L</a></li>

S0 that is now working, can I ask you to alter the query so it opens in the parent window if that is possible? Thanks.
 
<li><a id="btn1" class="button3" title="Download This Song" onclick="window.open(deCod(jwplayer(radio).getPlaylistItem().link));">D/L</a></li>
I'm surprised that works at all. window.open() expects an URL, not a JavaScript command. Magic... But if it works, it works. Obviously you get a new window here.

S0 that is now working, can I ask you to alter the query so it opens in the parent window if that is possible? Thanks.
Not sure what you mean with "the query". And I don't know what exactly that JS command is supposed to do.
But I think it should be as simple as removing what window.open from the line:

<li><a id="btn1" class="button3" title="Download This Song" onclick="deCod(jwplayer(radio).getPlaylistItem().link);">D/L</a></li>

(mind your parentheses )
 
By the query, I am referring to this line of code we're working on. the deCod function just returns a str from the parameter passed, in this case '.link' is the URL.This window is not the main site, it was opened from a parent, davidkempton.com and I'd like the click to open there rather in a third page. Sorry if my terminology is unclear, it has been years since I've dealt with code
 
I have not - yet. (Just woke up from a needed nap.) It took a minute to percolate thru, but I believe you have the solution. I think it will just need me to adjust the URL , I'll experiment with that now. I am pretty sure you are correct. Thanks. ECen if it doesn't work, I have what I NEED. IF this works, I also get what I WANT. <grin>
 
I have not - yet. (Just woke up from a needed nap.) It took a minute to percolate thru, but I believe you have the solution. I think it will just need me to adjust the URL , I'll experiment with that now. I am pretty sure you are correct. Thanks. ECen if it doesn't work, I have what I NEED. IF this works, I also get what I WANT. <grin>
Another option may be to add target="_self" to the link.
 
Thanks for your help. I'm not going to worry about the parent problem, This solution does what I need, and I have actual music to make. If someone wants to download a track, they can deal with a second window. Let's consider this closed, and thanks again.
 
Thanks for your help. I'm not going to worry about the parent problem, This solution does what I need, and I have actual music to make. If someone wants to download a track, they can deal with a second window. Let's consider this closed, and thanks again.
Yeah, makes sense. Making music is more important than changing websites. Please make sure to close the case by marking one of the comments (even if it's your own) as the solution.
 
Solution
Back
Top Bottom