/    Sign up×
Community /Pin to ProfileBookmark

Cant Access Objects In A Child Window

Let me put you in the picture on the main window i have 6 butons each of which call this function to open a child window i then intend to run some sql to add things to the childwindow depending on which button was presed and the date (i can do the SQl stuff) and i think i can access the child window using somevar = open(‘newchildwindow’ etc…) and then using that var ,and getElementById to drop everything to a ogject i can use.

BUT even in this very simple example i am working on it’s not working, or more to the point it works once then i and re call the fuction again from the main window i get a runtime error ‘obj’ is not a object. To get it to run again i have to close down the browser.

Any ideas what is going on, and how i can get around this

[ie5 + win 2000]

Thanks

[CODE]
function changeOrViewHistoricalvalues(dbfield) {
var LogedInUser=””, dbtable=””;

historicalpopupwindow = open(‘historicalChangePopup.html’, ‘historicalChangePopup’,’toolbar=no,location=no,sc
rollbars=no,resizable=no,width=515,height=400′)
historicalpopupwindow.focus();

obj=historicalpopupwindow.document.getElementById(‘historicalChange_title_text’);

obj.innerHTML= “<b>” + dbfield +” CHANGE LOG FOR ” + LogedInUser + “</b>”;
}
[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorApr 06.2004 — The statement

obj=historicalpopupwindow.document.getElementById('historicalChange_title_text');

is an asignment, not an equivalency!!!

That means obj take the value of the object's value, but it does not substitute the object itself!!

To solve that you must either write the full objects' method:

[code=php]
function changeOrViewHistoricalvalues(dbfield) {
var LogedInUser="", dbtable="";
historicalpopupwindow = open('historicalChangePopup.html', 'historicalChangePopup','toolbar=no,location=no,scrollbars=no,resizable=no,width=515,height=400')
historicalpopupwindow.focus();
historicalpopupwindow.document.getElementById('historicalChange_title_text').innerHTML= "<b>" + dbfield +" CHANGE LOG FOR " + LogedInUser + "</b>";
}
[/code]


or a function to setup the object

[code=php]
function setObj(id){
this.o = historicalpopupwindow.document.getElementById(id);
return this.o;
}
function changeOrViewHistoricalvalues(dbfield) {
var LogedInUser="", dbtable="";
historicalpopupwindow = open('historicalChangePopup.html', 'historicalChangePopup','toolbar=no,location=no,scrollbars=no,resizable=no,width=515,height=400')
historicalpopupwindow.focus();
obj = new setObj('historicalChange_title_text');
obj.innerHTML= "<b>" + dbfield +" CHANGE LOG FOR " + LogedInUser + "</b>";
}
[/code]
Copy linkTweet thisAlerts:
@numpty-spenceauthorApr 06.2004 — Thanks for the reply i tried both your solutions the first worked best i think the second one needed the reference to childwindow to be passed in not just the string name.

Any how the first solution will run but i am still in the same situation it will only run correctly the first time, any atempt to run it after this will cause a new run time error to appear "document.getElementById is not an object"

Do you know of any web sites that have a simular design, Or another way to acces page elements other that getElementById ?

Do you think it might be somthing to do with the way i close the child window? i have a button on the chilld and when clicked runs window.close();

Again thaks for the reply and i hope you can help further

Spence
Copy linkTweet thisAlerts:
@KorApr 07.2004 — hm... the reference is OK. In theory

If a popup is open using, say:

pgref = window.open([i]newURL,name_or_target,attributes[/i])

to referere something in the popup, starting from parent page:

pgref.document.[i]object[/i]

pgref.[i]a_function()[/i]

I don't know why your code don't work... It should be ok. Have you give the ID's to the objects? Are the ID's correct written? Try using Mozilla to see if there is a javascript error (have a javascript console which show the error more precisely than IE)

If not... hm....Well, try to refere back.

To refere something in the parent starting from popup:

window.opener.document.[i]object[/i]

window.opener[i]a_function()[/i]
×

Success!

Help @numpty-spence spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...