1

I have a script that has an Iframe with the source of foo.php.

I also have 5 links on my page that when clicked trigger a javascript function to change the source. The only issue is that after I click on one link and it changes the iframe, the next time I click on a link it doesn't change anymore.

Here is the javascript:

<script>
function changeSource(newSource) {
    parent.sec1.document.location=newSource;
}
</script>

and here is the html:

<a href="#calandar" onclick="changeSource('http://www.example.com/view.php')">Calandar</a><br />
<a href="#facebook" onclick="changeSource('http://www.facebook.com')">Facebook</a><br />
<a href="#gmail" onclick="changeSource('http://www.gmail.com')">Gmail</a><br />
<a href="#reddit" onclick="changeSource('http://www.reddit.com')">Reddit</a><br />
<a href="#twitter" onclick="changeSource('http://www.twitter.com')">Twitter</a><br />
</div>

<div id="sec1">
<iframe src="view.php" name="meat" width="100%" height="75%" ></iframe>
</div>

Thanks.

2 Answers 2

2

If i understood your question correctly, try adding id to that iframe, and do:


function changeSource(newSource) {
  document.getElementById('yourIframeId').src = newSource;
}

Hope it helps

Sign up to request clarification or add additional context in comments.

2 Comments

THANK YOU!!!!! I will accept your answer when the time limit finishes. But, thank you so so so much!
Glad to know it worked for you. We are here to share and help.. :)
2
<script>
function changeSource(newSource) {
    document.getElementById('my-iframe').src=newSource;
}
</script>
...
...
...
<iframe src="view.php" id='my-iframe' width="100%" height="75%" ></iframe>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.