PDA

View Full Version : Need help with javascript



rookie
08-01-2006, 12:16 AM
Being a rookie with javascript I in need of some expert advice.

Does anyone know if it is possible to continue to pass a javascript variable from one page to the next?
For an explanation read the following.


I am using a flash music player that excepts javascript parameters to manipulate the player (ie. start, stop, add song, etc...)

My goal is use a link to open the player in its own window, so a visitor can continue surfing the site and adding songs to the playlist from different pages (this is a website that hosts several musicians).

The problem I have run into is when you use the link to open the player in a seperate browser window

var player = window.open("wimpy.html","window_one","height=260,width=295");

and assign the window to a variable using javascript, the links on the current page work great but when moving to a different page that contains the same links to control the player don't work.

<a href="javascript:;" onClick="player.wimpy_clearPlaylist();"> Clear </a>

Does anyone know if it is possible to continue to pass a javascript variable from one page to the next?


Thank you in advance for any help,
Rookie

mwinter
08-01-2006, 12:44 AM
Does anyone know if it is possible to continue to pass a javascript variable from one page to the next?No, you cannot. When a document is unloaded, all of the script content is lost with it.

A workable solution here would be the use of frames, however there are definite drawbacks: the site itself will have to become frame-based. This will impact the content of the browser title bar and address bar, and will hamper bookmarking. Basically, it invokes all of the problems of current frame implementations.

The idea is to include a frame (or frameset) that is never reloaded. Rather than instantiating the player in a document from which a user will eventually leave whilst browsing the rest of the site, the frame is responsible instead. If a document needs to manipulate the player, it does it through the frame.

To make this work especially well with require a bit of server-side programming, too. Undoubtedly, the site will get requests to specific parts of the site. This will end up bypassing the initial frame, breaking the player. In that situation, it would be necessary to generate the frameset document dynamically, using the requested URL for the visible frame, rather than the default entry point.

It is up to you to determine whether this is a cost-effective solution. As a user, I would probably be more comfortable with links; I prefer to use Winamp and I'm quite happy to enqueue tracks myself. Then again, I'm probably not in your target audience. :)

Mike

rookie
08-01-2006, 01:05 AM
Thanks Mike,
I just came across an article that provided me with a solution using javascript.

http://www.thescripts.com/forum/thread89603.html

I thought about the frame idea, but really want to stay away from frames.

thanks

rookie
08-03-2006, 03:44 PM
So after playing around with what I thought was a solution I found that it only works in IE.

Does anyone know if you can (or how to) use a cookie to pass a variable containing a popup window name, so when you continue to browse a site the pages will remember the popwindow.

If I didn't explaing that clearly let me know.

Thanks

blm126
08-03-2006, 05:19 PM
I don't think you can pass the popup object in a cookie.


No, you cannot. When a document is unloaded, all of the script content is lost with it.

What if you pass the variable before the window is unloaded? Say you created the new window with a popup. Then closed the original window.

rookie
08-03-2006, 05:27 PM
Unfortunately the main window needs to remain open. Here is what I am try accomplish

http://www.theundersound.com/dev_band3.aspx?bandID=24

If you open the player (big black image beside the music section) you can then add song to the playlist via the "add to playlist" link, then you can continue to surf the site and add other songs from other bands.

But only with IE. Firefox (and I assume) other browser do not work and I am not sure why.

Any suggestions?

blm126
08-03-2006, 06:08 PM
I don't see any problem in firefox...

rookie
08-03-2006, 06:14 PM
You can add songs to the playlist from the page you launch the player, but if you go to another page it will not let you add a song using firefox but it will in IE.


Did you try that?

blm126
08-03-2006, 07:21 PM
Ok, I see now.

mwinter
08-03-2006, 07:43 PM
So after playing around with what I thought was a solution I found that it only works in IE.It was a hack, at best, which is why I would never have suggested it.


Does anyone know if you can (or how to) use a cookie to pass a variable containing a popup window name, so when you continue to browse a site the pages will remember the popwindow.Retaining the name won't reliably facilitate reacquiring a reference to the pop-up.

In theory, passing an empty string, rather than a URL, and the name of an existing window will return a reference to that window, rather than creating a new empty window. However, certain settings in Firefox (its relations, and possibly others browsers, too) will prevent this from occurring; a new window will always be opened instead.

Mike