473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

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

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
8 7069
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
В Суббота 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
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
В Суббота 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
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
В Суббота 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul Oakfleet | last post by:
The script below will disable Submit button until user accept terms, and will redirect user to another page after clicking on Submit button. The script seems to work fine on my PC (Windows XP,...
7
by: Donna Hawkins | last post by:
I want to use javascript to redirect to a URL which has been passed as a variable (in php). I have searched but cannot find any solution. I think this code is a basic redirect: <script...
0
by: WebHouse.Co | last post by:
Hi Sir I'm in my 2nd year in M.Sc. degree & I made a project about the powerful tools SQLXML 3.0 & updategram, so I made a list of programs which r they so similar to the example that using...
4
by: Max | last post by:
Hello, here a user control named aff.ascx : (this control is used to see the contains of a link) <%@ Control Language="VB" %> <script runat="server"> ' Insert user control code here Public...
5
by: accessman2 | last post by:
Hi, I have a question. I made the create the new user form. <script language="javascript"> function submitFrm() {
5
by: venner | last post by:
I'm having an issue with an ASP.NET website after upgrading to ASP.NET 2.0. The website makes use of a central authentication service (CAS) provided at the university I work for. Each page checks...
1
by: Trev | last post by:
Hi everyone, I'm trying to modify an existing piece of Javascript that will enable a redirect to a page based on IP address and/or keywords in the referrer; for instance, redirecting an existing...
5
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
I am trying to create ASPX code which will allow me to redirect a user to another site with POST data. I figure that the best way to do this is with JavaScript to the client. Here's what I'm doing:...
1
by: gnawz | last post by:
Hi guys, I have a couple of php files that perform various tasks. I will use fields in my system and provide code as well I need help as follows: My database contains the fields Category...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.