Jump to content

Choosing Where to Output JavaScript


thecard

Recommended Posts

I have 2 documents linked to a javascript.

Document "B" is in a Frame on Document "A".

 

Since both are linked to the javascript, how do I choose which document to output on?

 

e.g.

document.write("HELLO");

 

Can I choose to write that to either document?

Link to comment
Share on other sites

Well, my situation is rather complicated:

 

Both documents share the same javascript page, but the framed document (B) has to pass variables to the js by query strings (in the url) there are 20 variables. I need to collect these variables in the js and output them onto document A.

 

Thanks for your time.

I really dunno how to do this.

Link to comment
Share on other sites

I might be completely off topic now because I'm attempting to apply php logic to javascript, probably prove fatal lol.

 

As I said at the beginning I'm useless with JS, so sorry I can't help mate.

Try something like this in your actual document where you want it to show;

<script language="javascript" src="charcount.js">document.write("HELLO");</script>

 

If not have a play around with it and wait for one of the gurus to get back to you.

Link to comment
Share on other sites

I know that, but the javascript is connected to 2 documents:

 

The main page,

 

and the

 

Iframe.

 

The Iframe calls the function in the javascript, and this function must write to a div tag in THE MAIN DOCUMENT.

So? I don't see a problem there? I think your JavaScript is probably not coded correctly. Do you mind providing the HTML and JavaScript you use?

Link to comment
Share on other sites

The HTML (MAIN DOCUMENT):

<html>
<head>
<script type="text/javascript" src="js.js">
</script>
</head>
<body onLoad="doit();">
<a id="inner1"></a>
<a id="inner2"></a>
<a id="inner3"></a>
<a id="inner4"></a>
<a id="inner5"></a>
<a id="inner6"></a>
<a id="inner7"></a>
<a id="inner8"></a>
<a id="inner9"></a>
<a id="inner10"></a>
<a id="inner11"></a>
<a id="inner12"></a>
<a id="inner13"></a>
<a id="inner14"></a>
<a id="inner15"></a>
<a id="inner16"></a>
<a id="inner17"></a>
<a id="inner18"></a>
<a id="inner19"></a>
<a id="inner20"></a>

</body>
</html>

 

The PHP file (inside the iframe): I am not going to give you the exact code because it doesn't matter. The php does these actions mainly:

Links to the javascript.

Connects to a mysql database.

GETS the $_GET['dom'];

SELECTS 20 pieces of data from the database and passes them to the javascript in the dostuff function (which you can see in the javascript):

 

The Javascript:

function doit() {
    var mf = document.createElement("<iframe>");
    mf.src = "http://mydomain.com/frame.php?dom=" + window.location;
mf.width = "300px";
mf.height = "300px";
mf.frameborder="0";
mf.marginheight="0";
mf.marginwidth="0";
mf.id="mando";
    document.body.appendChild(mf);
}

function dostuff(nav1,nav2,nav3,nav4,nav5,nav6,nav7,nav8,nav9,nav10,nav11,nav12,nav13,nav14,nav15,nav16,nav17,nav18,nav19,nav20)
{

var n1 = nav1;
var n2 = nav2;
var n3 = nav3;
var n4 = nav4;
var n5 = nav5;
var n6 = nav6;
var n7 = nav7;
var n8 = nav8;
var n9 = nav9;
var n10 = nav10;
var n11 = nav11;
var n12 = nav12;
var n13 = nav13;
var n14 = nav14;
var n15 = nav15;
var n16 = nav16;
var n17 = nav17;
var n18 = nav18;
var n19 = nav19;
var n20 = nav20;
document.getElementById("inner1").innerHTML = n1;
} 

 

If you are correct the last line should put the variable n1 into the <a> tag with the id="inner1".

This line does not write anything to the document.

I know that vars n1 -> n20 do exist also because I have done lots of "alert tests" with them.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.