0

I got the following code:

<body> <div class="header"> <div class="logo"> title of page goes here </div> </div> <iframe src='sameserver.html'> <script> var pagetitle = 'page title'; </script> </iframe> </body> 

Now how can i get the javascript var placed inside the logo div? Is it even possible?

1
  • Do you want to put pagetitle variable inside logo div? Commented Aug 28, 2012 at 9:47

2 Answers 2

3

Ad ID to your logo, wait for iFrame to load and put variable to #logo

<body> <div class="header"> <div class="logo" id="logo"> title of page goes here </div> </div> <iframe src="sameserver.html" name="myIFrame"></iframe> <script type="text/javascript"> window.myIFrame.onload = function (){ title = window.myIFrame.pagetitle; document.getElementById('logo').innerHTML = title; } </script> </body> 

and sameserver.html:

<script> var pagetitle = 'page title'; </script> 
Sign up to request clarification or add additional context in comments.

2 Comments

ahh, c'mon .. the iframe contents where for eyes only, iframe contents should be in a separate file. I've modified.
Awesome solution! Just what i needed. Tnx Mihai lorga
1

yes it is possible. You can do like this.

parent.document.getElementById('someid').innerHTML=pagetitle; 

5 Comments

why would you use parent here?
I place that code in the parent right? after the iframe is loaded? someid would be the id of the iframe?
How would the above javascript look like in jquery? Or is the above also possible with jquery append?
$('#someid', window.parent.document).html(pagetitle);
or if it has some class then. $('.someid', window.parent.document).html(pagetitle);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.