I have a homepage with two frames. The left frame is the navigation menu with about 30 links to different websites. The right frame (frame name is "display") is used to display the content of websites when user click on the links on the navigation menu.
Left Navigation Menu This is part of the codes of the Left Navigation Menu:
<div id="LoadPage">
<a id="link1" href="http://domain1.com" targ开发者_如何转开发et="display">Website 1</a>
<br>
<a id="link2" href="http://domain2.com" target="display">Website 2</a>
</div>
When user click on the links on the Left Navigation Menu, the website will be displayed on the Right Frame (display) correctly.
Now, I wish that a random website will be display when the homepage load.
I try the following codes:
Here's part of the jQuery codes in Header Section:
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
.....................................
....................................
if (randomNumber = 1) {
window.location = $("a#link1").attr("href");
} else {
...........................
}
});
</script>
Problem: The problem with the above codes are that the website will display in the Left Navigation Window, not in the Right Window (display).
How can I add the target="display" attribute to this line of code so that the website will display in the Right Window (display)?
window.location = $("a#link1").attr("href");
Please help!
Best regards
Alex
A simple workaround would be to just invoke $("a#link1").click()
, instead of changing window.location
directly.
Assume your right iframe has an id 'right-iframe'. In left-iframe, you could do
$(window.parent.document).find('#right-iframe').attr('src', $("a#link1").attr("href"));
You need make sure your left-iframe domain and your root window domain are same.
精彩评论