Newbie: Manipulate document.write

J

Janwillem Borleffs

Haar said:
I have to simple scripts only containing :

Script1.js: document.write("<img src='http://www.domainname.com'>");

Script2.js: document.write("<img src='/images/13.gif'>");

Is it possible to manipulate the data (maybe in a 3. script)) so that the
browser reads: http://www.domainname.com/images/13.gif, without changing
script2 (on external server)

You could attempt the following:

window.onload = function () {
for (var i=0; i <document.images.length; i++) {
if (document.images.src == 'http://www.domainname.com') {
document.images.src += '/images/13.gif';
break;
}
}
}

This will leave you with two identical images, but you should only resort to
this solution when there is absolutely no way to edit script1.js...

JW
 
M

Michael Hall

if you make your .js files hold the info in an array
then you should be able to concatenate them together ...

1.js =

var content1 = ["http://www.domainname.com"]

2.js =

var content2 = ["/images/13.gif","/images/14.gif"]

join them like this ...

document.write("<img src='" + content1[0] + content2[0] + ">")

or

document.write("<img src='" + content1[0] + content2[1] + ">")
 
@

@SM

Haar a ecrit :
Hi

I have to simple scripts only containing :

Script1.js: document.write("<img src='http://www.domainname.com'>");

Script2.js: document.write("<img src='/images/13.gif'>");

Is it possible to manipulate the data (maybe in a 3. script)) so that the
browser reads: http://www.domainname.com/images/13.gif, without changing
script2 (on external server)

No you can't.

or ... something like

if(document.images) {
D = document.images;
for(var i=0;i<D.length;i++) {
el = D.src.subString(0,3);
if(el == 'http') script1 = D.src;
if(el == '/img') script2 = D.src;
}
}
}

And be sure you have any
- other image in the same document
at same address ( "/images/" )
- other at address beginning with "http"

Normaly you can't call from an other domain.

<html>
<script type="text/javascript"><!--

var scr0 = "<img src='";
var scr1 = "'>";
var script1 = 'http://www.domainname.com';
var script2 = '/images/13.gif';

function myWrite(text1,text2) {
document.write(scr0+text1+text2+src1); }

function searchImg(docuLocation) {
if(docuLocation.document.images) {
D = docuLocation.document.images;
for(var i=0;i<D.length;i++) {
if(D.src.subString(0,3) == 'http')
script1 = D.src;
if(D.src.subString(0,3) == '/img')
script2 = D.src;
}
}
}
// --></script>

<h2> without calling the other doc </h2>
<script type="text/javascript"><!--
myWrite(script1,'');
document.write('<br>');
myWrite(script2,'');
document.write('<br>');
myWrite(script1,script2);
// --></script>

<h2> calling other doc openned in 2nd frame of this parent </h2>
<script type="text/javascript"><!--
searchImg('parent.frames[1]');
myWrite(script1,'');
document.write('<br>');
myWrite(script2,'');
document.write('<br>');
myWrite(script1,script2);
// --></script>
</html>


-- -----
@SM
move away *OTEZ-MOI* from my reply url
 
H

Haar

@SM said:
Haar a ecrit :
Hi

I have to simple scripts only containing :

Script1.js: document.write("<img src='http://www.domainname.com'>");

Script2.js: document.write("<img src='/images/13.gif'>");

Is it possible to manipulate the data (maybe in a 3. script)) so that the
browser reads: http://www.domainname.com/images/13.gif, without changing
script2 (on external server)

No you can't.

or ... something like

if(document.images) {
D = document.images;
for(var i=0;i<D.length;i++) {
el = D.src.subString(0,3);
if(el == 'http') script1 = D.src;
if(el == '/img') script2 = D.src;
}
}
}

And be sure you have any
- other image in the same document
at same address ( "/images/" )
- other at address beginning with "http"

Normaly you can't call from an other domain.

<html>
<script type="text/javascript"><!--

var scr0 = "<img src='";
var scr1 = "'>";
var script1 = 'http://www.domainname.com';
var script2 = '/images/13.gif';

function myWrite(text1,text2) {
document.write(scr0+text1+text2+src1); }

function searchImg(docuLocation) {
if(docuLocation.document.images) {
D = docuLocation.document.images;
for(var i=0;i<D.length;i++) {
if(D.src.subString(0,3) == 'http')
script1 = D.src;
if(D.src.subString(0,3) == '/img')
script2 = D.src;
}
}
}
// --></script>

<h2> without calling the other doc </h2>
<script type="text/javascript"><!--
myWrite(script1,'');
document.write('<br>');
myWrite(script2,'');
document.write('<br>');
myWrite(script1,script2);
// --></script>

<h2> calling other doc openned in 2nd frame of this parent </h2>
<script type="text/javascript"><!--
searchImg('parent.frames[1]');
myWrite(script1,'');
document.write('<br>');
myWrite(script2,'');
document.write('<br>');
myWrite(script1,script2);
// --></script>
</html>


-- -----
@SM
move away *OTEZ-MOI* from my reply url



I think i understand where you are going, maybe its easier if you see the
image I am trying to access.

The 13.gif Is a weather icon, and is on the button of this page
http://www.dr.dk/nyheder/

It can (depending on the weather) be any thing from
http://www.dr.dk/pubs/nyheder/html/nyheder/vejret/grafik/vejr_ikon/1.gif to
22.gif

Now, on the page in the source code it is called my this simple script
http://www.dr.dk/pubs/nyheder/html/nyheder/vejret/dagensvejrikon.js

Which simply states document.write("<img
src='/pubs/nyheder/html/nyheder/vejret/grafik/vejr_ikon/TODAYS-NUMBER-GOES-H
ERE.gif'>");

So if I call the script from my own page I will look for the image on my one
HD and not at the domain (www.dr.dk)

As I see your script, (bare in mind I am new at this) it does what i asked
for, but only if for 13.gif (only works until the weather changes J)

From you're script:

<html>

<script type="text/javascript"><!--



var scr0 = "<img src='";

var scr1 = "'>";

var script1 = 'http://www.dr.dk';

var script2 = '/pubs/nyheder/html/nyheder/vejret/grafik/vejr_ikon/13.gif';



function myWrite(text1,text2) {

document.write(scr0+text1+text2+scr1); }



function searchImg(docuLocation) {

if(docuLocation.document.images) {

D = docuLocation.document.images;

for(var i=0;i<D.length;i++) {

if(D.scr.subString(0,3) == 'http')

script1 = D.scr;

if(D.scr.subString(0,3) == '/img')

script2 = D.scr;

}

}

}

// --></script>



<h2> without calling the other doc </h2>

<script type="text/javascript"><!--



document.write('<br>');

myWrite(script1,script2);

// --></script>





</html>

works great if the image is known.

so the question is, can I run the script, dagensvejrikon.js, and then make
the "document.write-part" act as script2 in you're script?
 
@

@SM

Haar a ecrit :
I think i understand where you are going, maybe its easier if you see the
image I am trying to access.

The 13.gif Is a weather icon, and is on the button of this page
http://www.dr.dk/nyheder/

It can (depending on the weather) be any thing from
http://www.dr.dk/pubs/nyheder/html/nyheder/vejret/grafik/vejr_ikon/1.gif to
22.gif

Now, on the page in the source code it is called my this simple script
http://www.dr.dk/pubs/nyheder/html/nyheder/vejret/dagensvejrikon.js

Ah ! OK !
It is not kind of you to catch works of others !

Try this :

[image_weather.htm]
<BASE HREF="http://www.dr.dk/">
<html>
Here is wheather<br>today on Danmark<br>
<script type="text/javascript"
src="http://www.dr.dk/pubs/nyheder/html/nyheder/vejret/dagensvejrikon.js";>
</script>
</html>

in addition you can try :
(1st & 2nd files in same folder)

[danish_weather.htm]
<html>
<h1>Danish Weather</h1>
<iframe name="maframe" width=100 height=150 border=1 src="image_weather.htm">
Votre navigateur ne supporte pas les i-frames<br>
Iframes non supported<br>
<a href="image_weather.htm" target="see"
onclick="window.open('','see','width=80,height=60');">To see weather on Danmark</a>
</iframe>
</html>



-- '_' and every uppercase letters in urls are to move away
******* (modifier les urls en enlevant les majuscules) *******
Stéphane MORIAUX : mailto:stephaneOTER (e-mail address removed)
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephanePOINT ICImoriaux/internet/
**************************************************************
 
T

Thomas 'PointedEars' Lahn

Michael said:
if you make your .js files hold the info in an array
then you should be able to concatenate them together ...

1.js =

var content1 = ["http://www.domainname.com"]

There is exactly no need to define an array *here* only
for the purpose of concatenation. A string will suffice.
[top post]

Please do not do this. You are wasting scarce resources.


PointedEars
 
J

Jim Ley

Michael said:
if you make your .js files hold the info in an array
then you should be able to concatenate them together ...

1.js =

var content1 = ["http://www.domainname.com"]

There is exactly no need to define an array *here* only
for the purpose of concatenation. A string will suffice.

However an array .join('')'s is generally considered much faster in
execution, so it can be useful.

Jim.
 
T

Thomas 'PointedEars' Lahn

Jim said:
if you make your .js files hold the info in an array
then you should be able to concatenate them together ...

1.js =

var content1 = ["http://www.domainname.com"]

There is exactly no need to define an array *here* only
for the purpose of concatenation. A string will suffice.

However an array .join('')'s is generally considered much faster in
execution, so it can be useful.[/QUOTE]

There is nothing to be joined here, the first array
contains only one element. Using it here is wasting
memory, for a String object and an Array object,
while a String object would suffice.

Array.join(...) is faster in execution than *what*?


PointedEars
 
J

Jim Ley

There is nothing to be joined here, the first array
contains only one element.

Sure, but you then started talking about concatenation, the snippet
contains no concatentation so you were obviously thinking about
something else...
Using it here is wasting
memory, for a String object and an Array object,
while a String object would suffice.

Array.join(...) is faster in execution than *what*?

Than repeated concatenation, using an Array and Join is generally
faster than a string for concatenation.

Jim.
 
T

Thomas 'PointedEars' Lahn

,-<[email protected]>
| [...]
| var content1 = ["http://www.domainname.com"]
Sure, but you then started talking about concatenation,

About this:

,-<[email protected]>
| [...]
| document.write("<img src='" + content1[0] + content2[0] + ">")
|
| or
|
| document.write( said:
the snippet contains no concatentation

Well, it does.
Than repeated concatenation, using an Array and Join is generally
faster than a string for concatenation.

Full ACK. If that would have been used here ...


PointedEars
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
Thomas 'PointedEars' Lahn
Michael Hall wrote:
[top post]

Please do not do this. You are wasting scarce resources.

You are being stupid again. Top posting does not waste resources.

It is over-quoting which wastes resources, and top-posting is no more
than a common precursor to that.

Careless and inadequate posting, such as yours, wastes resources.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top