By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,519 Members | 1,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,519 IT Pros & Developers. It's quick & easy.

How could I redirect document.write to a new page/tab?

P: n/a
Hi,

I am trying make some multimedia files playable from my website. So far, I
am able to generate dynamically a new page containing the right <embed>
section. However, when I load my script, it overwrites the current page. Is
there any way I could load a new tab or window, and put the new content
into it?

Here is the script I am using right now:

<script language="JavaScript"><!--
function playmedia() {
newwindow=window.open();
if (window.focus) {newwindow.focus()}
document.write('<html>')
document.write(' <head>')
document.write(' <title>Media player</title>')
document.write(' </head>')
document.write(' <body bgcolor="#A0A0FF" text="#000000">')
document.write(' <center>')
document.write(' <h2>Playing the media file... ♫</h2><br>')
document.write(' <!-- show play buttons, autostart and loop once -->')
document.write(' <embed src="title.mid" hidden=false autostart=true
loop=1 autosize=1>')
document.write(' </center>')
document.write(' </body>')
document.write('</html>')
}
//--></script>

Any ideas? :-)

Best regards,
Mateusz Viste
Sep 6 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
SAM
Mateusz Viste a crit :
Hi,

I am trying make some multimedia files playable from my website. So far, I
am able to generate dynamically a new page containing the right <embed>
section. However, when I load my script, it overwrites the current page. Is
there any way I could load a new tab or window, and put the new content
into it?

Here is the script I am using right now:

<script language="JavaScript"><!--
No ! no more used, prefer :

<script type="text/javascript">

function playmedia() {
newwindow=window.open();
if (window.focus) {newwindow.focus()}
// prefer isnstead :

if (typeof newwindow == 'undefined' || newwindow.closed)
newwindow = window.open()

// then, because you need to write in the document
// of the window 'newwindow' :

var document = newwindow.document;
document.open();
document.write('<html>')
document.write(' <head>')
document.write(' <title>Media player</title>')
document.write(' </head>')
document.write(' <body bgcolor="#A0A0FF" text="#000000">')
document.write(' <center>')
document.write(' <h2>Playing the media file... ♫</h2><br>')
document.write(' <!-- show play buttons, autostart and loop once -->')
document.write(' <embed src="title.mid" hidden=false autostart=true loop=1 autosize=1>')
document.write(' </center>')
document.write(' </body>')
document.write('</html>')
document.close();
newwindow.focus();
}
</script>
Any ideas? :-)
in your code 'document' is the document of the window which has the
script and not the document of your new window.
--
sm
Sep 6 '08 #2

P: n/a
В Суббота 06 сентября 2008 16:55, SAM писал:
in your code 'document' is the document of the window which has the
script and not the document of your new window.
Hi,

Thank you a lot for your comments!
About the main issue: indeed, you are right :-) I just
replaced "document.write" by "newwindow.document.write", and it works
fine :-)

I would have a secondary question (still about the same script). I am
triggering my script using a button:
<form><input type="button" value="Play" onClick="playmedia()"></form>

Is there any way I could do that using a link?

Best regards,
Mateusz Viste
Sep 6 '08 #3

P: n/a
On Sep 6, 9:26pm, Mateusz Viste
<mateusz.visteATmailDO...@trashymail.comwrote:
06 2008 16:55, SAM :
in your code 'document' is the document of the window which has the
script and not the document of your new window.

Hi,

Thank you a lot for your comments!
About the main issue: indeed, you are right :-) I just
replaced "document.write" by "newwindow.document.write", and it works
fine :-)

I would have a secondary question (still about the same script). I am
triggering my script using a button:
<form><input type="button" value="Play" onClick="playmedia()"></form>

Is there any way I could do that using a link?

Best regards,
Mateusz Viste
<form action="#" id="frm">
<div id="dummy">
<a href="#" onclick="playmedia();">Play</a>
</div>
</form>

Also make sure your documents are validated against the DOCTYPE you
are using. "action" is a mandatory attribute of the <formtag. Make
sure the HTML event handler attributes are all lowercase i.e. onclick
instead of onClick. The comp.lang.javascript FAQ is a must read.
< http://www.jibbering.com/faq/ >

Regards,
/sasuke
Sep 6 '08 #4

P: n/a
В Суббота 06 сентября 2008 19:42, uz***************@gmail.com писал:
<form action="#" id="frm">
<div id="dummy">
<a href="#" onclick="playmedia();">Play</a>
</div>
</form>

Also make sure your documents are validated against the DOCTYPE you
are using. "action" is a mandatory attribute of the <formtag.
Great, all is working now :-)
Thank you, guys!

Best regards,
Mateusz Viste
Sep 6 '08 #5

P: n/a
SAM
Mateusz Viste a écrit :
В Суббота 06 сентября 2008 16:55, SAM писал:
>in your code 'document' is the document of the window which has the
script and not the document of your new window.

Hi,

Thank you a lot for your comments!
About the main issue: indeed, you are right :-) I just
replaced "document.write" by "newwindow.document.write", and it works
fine :-)
Don't forget to add at end of your writting :

newwindow.document.close();

If not, my Fx never stops to wait the end of document.
I would have a secondary question (still about the same script). I am
triggering my script using a button:
<form><input type="button" value="Play" onClick="playmedia()"></form>
<form action="javascript:playmedia()">
<input type="submit" value="Play">
</form>

Is there any way I could do that using a link?
<a href="errorJS.htm"
onclick="playmedia(); return false;">Play</a>
To play sound with 'embed' in same page (same window) :

<html>
<script type="text/javascript">
function playmedia(title) {
var E = document.createElement('embed');
E.src = title.href;
E.hidden = false;
E.controller = true;
E.autostart = true;
E.loop = 1;
E.autosize = 1;
if(document.getElementById('player'))
document.getElementById('player').parentNode.repla ceChild(
E, document.getElementById('player'));
else
document.body.appendChild(E);
E.id = 'player';
return false;
}
</script>
<h2>Play sounds</h2>
<ul>
<li><a href="sound1.mid" target="play"
onclick="return playmedia(this)">sound 1</a></li>
<li><a href="sound2.mid" target="play"
onclick="return playmedia(this)">sound 2</a></li>
<li><a href="sound3.mid" target="play"
onclick="return playmedia(this)">sound 3</a></li>
</ul>
</html>
Embed it deprecated !
--
sm

Sep 6 '08 #6

P: n/a
В Суббота 06 сентября 2008 20:39, SAM писал:
>Is there any way I could do that using a link?

<a href="errorJS.htm"
onclick="playmedia(); return false;">Play</a>
So far, so good :-)
I had some formatting troubles using FORM, but with the method above it
works just fine :-)

My scripting is finalized now.
I needed that stuff for
http://viste.homeip.net/mateusz/nes/htm_roms/smb3.htm (and all sub-pages)

Again,
thanks guys ;-)

Best regards,
Mateusz Viste
Sep 6 '08 #7

P: n/a
In comp.lang.javascript message <48**********************@news.free.fr>,
Sat, 6 Sep 2008 14:33:32, Mateusz Viste <mateusz.visteATmailDOTru@trashy
mail.composted:
>
I am trying make some multimedia files playable from my website. So far, I
am able to generate dynamically a new page containing the right <embed>
section. However, when I load my script, it overwrites the current page. Is
there any way I could load a new tab or window, and put the new content
into it?
See NewPage and/or FreshPage in the include1.js section of <URL:http://w
ww.merlyn.demon.co.uk/js-nclds.htm>, with the routines they call.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 6 '08 #8

P: n/a
On Sep 7, 12:55*am, SAM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
Mateusz Viste a crit :
[...]
>
* document.write('<html>')
* document.write(' *<head>')
* document.write(' * *<title>Media player</title>')
* document.write(' *</head>')
* document.write(' *<body bgcolor="#A0A0FF" text="#000000">')
* document.write(' *<center>')
* document.write(' * *<h2>Playing the media file... ♫</h2><br>')
* document.write(' * *<!-- show play buttons, autostart and loop once -->')
* document.write(' * *<embed src="title.mid" hidden=false autostart=true loop=1 autosize=1>')
* document.write(' *</center>')
* document.write(' *</body>')
* document.write('</html>')
It is more efficient to create a single string and use document.write
once rather than make several calls. The center element is
deprecated, use a suitably styled div element. It doesn't seem
sensible to write comments.

e.g.

document.write(
'<html><head><title>Media player</title>' +
'</head><body bgcolor="#A0A0FF" text="#000000">' +
'<div style="text-align: center;">' +
'<h2>Playing the media file... ♫</h2><br>' +
'<embed src="title.mid" hidden=false autostart=true' +
' loop=1 autosize=1></div></body></html>'
);
--
Rob
Sep 7 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.