View Full Version : Function calling

06-21-2010, 01:17 PM
Below is the script or function that will add song the the player if the player is embeded in iframe.

<a href="javascriptarent.iframe.EP_addTracks('ep_player1', '<track><location>mp3/welcome.mp3</location><title>Added to begin.</title><creator>Track</creator></track>', 0);">add track to begin</a>

Can you tell me what would be the function if the player is embedded in popup page (player.html)

06-21-2010, 03:34 PM
That's pretty non-standard code. Without some initialization it would probably give you a 404 not found when you clicked on that link.

So, either you made a typo copying it, and/or there was some problem with the editor, or we need to see more code. I suspect it should be:

<a href="javascript:parent.iframe.EP_addTracks('ep_pla . . .

If so, when you open the pop up, it should be via the window.open() method, something like:

<a href="player.html" onclick="window.open(this.href, '_blank'); return false;">Player</a>

You should assign it to a global variable, player here. Also include some specifications to prevent it from opening in a new tab:

<a href="player.html" onclick="player = window.open(this.href, '_blank', 'width=300, height=200'); return false;">Player</a>

Now you can do:

<a href="javascript:player.EP_addTracks('ep_player1', '<track><location>mp3/welcome.mp3</location><title>Added to begin.</title><creator>Track</creator></track>', 0);">add track to begin</a>

This assumes that the EP_addTracks() function is on player.html and that the path to the mp3 specified is valid for player.html.

If the window hasn't been opened yet, there will be an error. There are various ways to check for that.

I'd think something like:

<a href="javascript:if(typeof player !== 'undefined' && typeof player.EP_addTracks === 'function')player.EP_addTracks('ep_player1', '<track><location>mp3/welcome.mp3</location><title>Added to begin.</title><creator>Track</creator></track>', 0);else alert('You Need to Open the Player');">add track to begin</a>

06-21-2010, 06:23 PM
First thank you for reply John.
Well I do not have any knowledge of javascript.

The player i am using is e-phonic.

Yes I copy pasted the script but due to the smiley i was not able to use :p

correct code as you have mentioned is below where the player and the below code are in the same page. which enable me to add tracks without any issue.

<a href="javascript:player.EP_addTracks('ep_player1', '<track><location>mp3/welcome.mp3</location><title>Added to begin.</title><creator>Track</creator></track>', 0);">add track to begin</a>

when the player is in iframe then the code is

<a href="javascript:parent.iframe.EP_addTracks('ep_player1', '<track><location>mp3/welcome.mp3</location><title>Added to begin.</title><creator>Track</creator></track>', 0);">add track to begin</a>

In my website(index.html) i will have "launch player button" which will popup the player.html.

now I need to add song to the player (player.html )

The code and functions are one the index page, when i click "Add track" the respective song needs to be loaded into the playlist.

Player.html only has contents related to load the flash player

please provide me full code.

06-21-2010, 06:44 PM
Well John the last code you have provided worked with some limitations that when i navigate from index page to another page(latest songs.html) and click track to begin, I am getting alert "you need to open the player". where the player has already been popped up from index page.

I need to open the player once and navigate to inner pages and then add songs of liking.

Do i need to have session or something to tell other inner pages in my website that player is already open.

06-21-2010, 08:00 PM
Inner pages? Um, a session would require server side code and I'm not aware of any that can pass a window object. Perhaps asp.NET could.

There is probably a way to work it out with just javascript. But I promise you it won't be pretty. It would involve instead of navigating away from the index page, covering it in an iframe and making it look like the index page wasn't there. You would then load all other pages into this iframe, except when returning to the index page, in which case you would hide the iframe, revealing the index page underneath. Open player.html from the index in the same way we have been. Then you would be accessing top.player.EP_addTracks().

The easiest way would be to put the player.html in a frame in a frameset so it would always be there. You could then access it as top.frameName.EP_addTracks() from any page loaded into any other frame (you would probably only need one other frame) in the frameset. frameName would be the name of the frame with the player.html in it.

06-21-2010, 08:40 PM
Well well well designing a website on asp.net is very very difficult.
About frameset, i have tried first. because frameset uses straight line i focused on Iframes.

When djr33 told me that it is not possible to make iframe static(where iframe loads player) and other pages dynamic.the inverse is possible.

John, is there a way to make a particular section(300 x 300 pixels) of the website always
be static (does not get loaded again if navigated to inner pages) with Ajax script or something else.

If you have enough time please take a look at the url http://www.planetradiocity.com/radiolounge/index.php

it is not my website, but somewhat related to what i want for my website.

Replacing the google rectangle ad with my player.

He his not using frames or framset but the top section of the page is static (from player to e-mail signup block). which script he is using.