...

View Full Version : How to pass value to newly opened webpage?



charles22
11-17-2010, 06:16 AM
Hi All,

Can anyone here help me to resolve my problem?

Problem: I have 10 links on my webpage which opens different media files. When I embed all those media files my webpage takes too much time to load.

My requirement: To overcome this what I need is I will place 10 different hypertexts (images), which when clicked will open another page (Play_Chord.html) in which the media file will be played. Opening a window on click is easy but where I am stuck is I need to pass the value (media file name) to the new window (which will open) so that it can play that media file.

I am new to javascript I have searched it net but could not get the working solution.


My Code (Main.html)



<html>
<head>

<script language="javascript">
function OpenPlayer(File_Name)
{
var w=400;
var h=200;
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);

window.open ("http://mywebsite.com/Play_Chord.html", 'mywindow', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
</script>


</head>
<body>

<img src="http://mywebsite.com/abcd.jpg" border=0 title="abcd" onClick = " OpenPlayer ('C-Maj.mid')" ></a>

</body>
</html>


My Code (Play_Chord.html)



<html>
<head>
</head>

<body>

<object id="MediaPlayer1"
classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"
standby="Loading Microsoft® Windows® Media Player components..."
type="application/x-oleobject" align="middle">
<param name="FileName" value="http://mywebsite.com/File_Name.mid">
<param name="autostart" VALUE="false">
<param name="ShowControls" VALUE="true">
<param name="ShowStatusBar" value="false">
<param name="ShowDisplay" VALUE="false">
<param name="AutoRewind" VALUE="true">
<embed type="application/x-mplayer2" pluginspage = "http://www.microsoft.com/Windows/MediaPlayer/"
src="http://mywebsite.com/File_Name.mid"
autostart="true" align="middle" width="100" height="45" defaultframe="rightFrame" showstatusbar="false">
</embed>
</object>

</body>
</html>


Please help

Charles

Philip M
11-17-2010, 07:33 AM
Several ways.
a) window.name
b) query string
c) cookie.

This topic has been covered very many times in this forum. Did to try using the search feature?

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

charles22
11-17-2010, 07:38 AM
@ Philip M : I have no intention to hurt anyone here. Anyways I have updated my previous thread.

Could you please suggest how it will go with query string?

Philip M
11-17-2010, 08:43 AM
Some useful tutorials:-

http://javascript.about.com/library/blqs.htm

http://www.javascriptkit.com/javatutors/send1.shtml

http://www.htmlgoodies.com/beyond/javascript/article.php/3471111

http://www.boutell.com/newfaq/creating/scriptpass.html

http://javascript.internet.com/forms/passing-values.html

But the best and most reliable method (especially in this case) is to use a cookie. There are many examples posted in this forum.

charles22
11-17-2010, 09:33 AM
Hi

I tried a lot and have stuck in this new situation. Now I am able to pass the file name but not able to see media player in the new window. Neither media file is playing. Something wrong with document.getElementById('music1').innerHTML :(

Code: Main.html



<html>
<head>

<script language="javascript">
function OpenViewer(ViewerUrl)
{
var w=400;
var h=200;
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);

window.open ("http://www.MyWebsite.com/"+ViewerUrl, 'mywindow', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
</script>

</head>
<body>

<input type="submit" value="Play Chord" onClick = "OpenViewer('Play-Chord.html?ChordName=C-Major')"/>

</body>
</html>


Code: Play-Chord.html



<html>
<head>

<script type="text/javascript" language="JavaScript1.2">

function GetParam(name)
{
var start=location.search.indexOf("?"+name+"=");
if (start<0) start=location.search.indexOf("&"+name+"=");
if (start<0) return '';
start += name.length+2;
var end=location.search.indexOf("&",start)-1;
if (end<0) end=location.search.length;
var result=location.search.substring(start,end);
var result='';
for(var i=start;i<=end;i++)
{
var c=location.search.charAt(i);
result=result+(c=='+'?' ':c);
}
return unescape(result);
}

aUEntString=GetParam('ChordName');
aUStrStartPos=aUEntString.indexOf('D');
aUStrEndPos=parseInt(aUEntString.length);
aUChordName=aUEntString.substr(aUStrStartPos, aUStrEndPos);

alert("ChordName=" + aUChordName);

document.getElementById('music1').innerHTML= "<embed type='application/x-mplayer2' pluginspage = 'http://www.microsoft.com/Windows/MediaPlayer/' src='" + aUChordName + "' autostart='true' align='middle' width='100' height='45' defaultframe='rightFrame' showstatusbar='false'></embed>";

</script>

</head>
<body>

<span id="music1"></span>

</body>
</html>



Please help

Charles



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum