...

View Full Version : Positioning in javascript document.write("<... Help! please



mx-guest2004
06-11-2004, 07:43 AM
Hi!
I don't know much about javascripts but hope to get some help:
I have this code:


{document.write("<embed name='midi' src="+mide+" loop='1' autostart='true' hidden='false' width='300' height='100'>")}

I want to define a position for this object on the screen. How and where can I put a position? I have tried with document.left=400 or document.style.left=400, NO luck.

Thanks for your help.
mx-guest2004

glenngv
06-11-2004, 08:22 AM
Just put that wherever you want the player to be displayed. But if you want it exactly at 400x400 position, you can put it in a absolutely positioned div.

<div style="position:absolute;left:400px;top:400px;">
<script type="text/javascript">
document.write('<embed name="midi" src="'+mide+'" loop="1" autostart="true" hidden="false" width="300" height="100">');
</script>
</div>

Kor
06-11-2004, 08:28 AM
If static positioning, use CSS

<div style="position:absolute;left:200;top:200">
<script>.....</script>
</div>

mx-guest2004
06-11-2004, 08:43 AM
Thanks glenngv and kor; :)
This document.write... is in a function and activates by a function call. If the condition is true, then it writes.
Can I put glenngv's code in that function? Where?
I have:
<script>
function()
..
..
document.write...
</script>

mx-guest2004

Kor
06-11-2004, 08:48 AM
than use

<script type="text/javascript">
document.write('<div style="position:absolute;left:200;top:200"><embed name="midi" src="'+mide+'" loop="1" autostart="true" hidden="false" width="300" height="100"></div>');
</script>

mx-guest2004
06-11-2004, 09:42 AM
Kor,
Sorry I ask this stupid question:
My script begins with <script language="Javascript">
I put your last code between as this but it didn't work. Whta did I do wrong?

mx-guest2004

<script language="Javascript">
function()
...
<script type="text/javascript">
document.write('<div style="position:absolute;left:200;top:200"><embed name="midi" src="'+mide+'" loop="1" autostart="true" hidden="false" width="300" height="100"></div>');
</script>
</script>

glenngv
06-11-2004, 09:51 AM
You can't put <script> tag within another <script> tag. You only need one.

mx-guest2004
06-11-2004, 09:59 AM
It doesn't work with <script type="text/javascript> neither.
I put the whole code here and I hope it helps to see the whole:
It works without positioning and the device appears in the left corner of the screen, if the condition is true.

<html>
<head>
<script type="text/javascript>

<!--
var param = 1
function myPlay(par) {

if (par!=param) {return}

var currentdate = 0
var theranmidi = " "
var core = 0

function StringArray (n) {
this.length = n;
for (var i =1; i <= n; i++) {
this[i] = ' '

}
}

midi = new StringArray(1)
mid0 = "http://www.greektownimports.com/music/solobouzouki.ram"
//mid1 = "http://www.greektownimports.com/music/solobouzouki.ram"
//mid2 = "http://www.greektownimports.com/music/solobouzouki.ram"
midr = 0
now=new Date()
midr=(now.getSeconds() )%1
mide = " "
if (midr == 0)
{{mide = mid0}
name =("lalala")}
if (midr == 1)
{{mide = mid1}
name =("test")}
if (midr == 2)
{{mide = mid2}
name =("testtesttset")}


{document.write('<div style="position:absolute;left:200;top:200"><embed name="midi"

src="'+mide+'" loop="1" autostart="true" hidden="false" width="300" height="100"></div>');
}

}

</script>


</head>
<body>

</body>
</html>

glenngv
06-11-2004, 10:25 AM
<script type="text/javascript">

mx-guest2004
06-11-2004, 10:26 AM
It works now. Stupid of me to forget " in the <script type="text/javascript">
Thanks very much glenngv and kor
:) :)

mx-guest2004

mx-guest2004
06-11-2004, 11:54 AM
It's me again.
The object appears in the right position but only on a new page. I have to click back button to get back to my main page.
I have other text and images in my main page and want to have this object on the same page.

mx-guest2004

glenngv
06-14-2004, 02:55 AM
Since you have document.write in the script, put it inside the <body> tag instead of the <head>.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum