English 中文(简体)
从母体中获取预载图像也用于儿童文字。 如何?
原标题:Accessing preloaded images from parent script too use in child script. How?
  • 时间:2010-03-18 18:19:27
  •  标签:
  • javascript

I m trying to update an image in a parent window with clickable links in a child window. I ve preloaded the images in the parent window with one javascript file. "scriptss.js" My problem is I need to access the preloaded images of the parent window with the childscript "scriptremote.js" Thanks again for all the JS Help! The JS (scriptss.js)

var newWindow = null;
window.onload = init;
var i = 0;
image_object = new Image();
myImages = new Array(); // declare array
myImages[0]="images/img1.jpg"  // load array
myImages[1]="images/img2.jpg" 
myImages[2]="images/img3.jpg"     
myImages[3]="images/img4.jpg"
myImages[4]="images/img5.jpg"
myImages[5]="images/img6.jpg"

括号中的超文本:

<img src="" width="200px" height="200px" id="myimage" name="myimage" /></img>

The following s The JS for child即:

window.onload = init;

function init()
{
}

function first_image()
{
window.parent.image_object.src = myImages[3]; //Problem happens here I think
document.getElementById("myimage")window.parent.src = window.parent.image_object.src;

}

无线儿童窗口

<h1>My Remote</h1>
<a href="#" id="first" onclick="first_image()" >First Image</a>
</br>
最佳回答

在您的亲身窗口中,你实际上没有预先掌握自己的形象。 您应当做这样的事。

myImages = new Array(); // declare array
myImages[0] = new Image()
myImages[0].src = "images/img1.jpg"
//etc...

现在,你们有一系列图像物体。

从孩子的窗户(一机)看,你可以参考这些物品,把rc子归咎于你在父母中的形象。

window.parent.document.getElementById( myImage ).src = window.parent.myImages[n].src;
// where n is the index of the image you want to display

If your child window is a popup then replace parent with opener Also you don t need a closing tag for <img />, it s self closing

问题回答
window.parent.image_object.src = myImages[3];

looks

window.parent.image_object.src = window.parent.myImages[3];

由于<代码>image_object和myImages都在同一个联合材料中界定。 后一行指向:

document.getElementById("myimage")window.parent.src = 
                                                 window.parent.image_object.src;




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签