/    Sign up×
Community /Pin to ProfileBookmark

Using Initialised variable in window.open Method

Dear all,

I would like to use pre defined variable in [B]window.open[/B] method which is prompting me [B]undefined[/B] in [B].js[/B] page which is working with by calling other functions. Please find my below code and fix errors where am I wrong or any ideas…

[code]
function textlabel()
{
myRef = window.open(”,’mywin’,’left=20,top=20,width=500,height=500,toolbar=1,resizable=0′)
docRef = myRef.document.open(“text/html”,”replace”);
myRef.document.write(‘<html><head><b> Text Label Properties:</b></br></br> <title>Text Label Properties</title> </head>’
+'<body bgcolor=white onLoad=”self.focus()” form=txtlblfrm>’
+’The position of the object, defined by its coordinates</br> in the 3D world. Can be one of the following: </br> <b> SGCoord3D/ SGCoord2D/ SGPosition </b></br></br></br> <b> X-Position: </b><input type=”text” name=”lblxpos”/></br></br>’
+'<b> Y-Position: </b><input type=”text” name=”lblypos”/></br></br>’
+'<b> Label Text: </b><input type=”text” name=”lbltxt”/></br></br>’
+'<input type=”button” value=”Submit” onclick=”cretxtlbl()” src=”global()”><nbsp>’
+'<input type=”button” value=”Cancel” onclick=””>’
+'<script language=”javascript”> function cretxtlbl() { var xpos = document.all[“lblxpos”].value; alert(xpos); var ypos = document.all[“lblypos”].value; alert(ypos); var txt = document.all[“lbltxt”].value; alert(txt); var label = globe.creator.createTextLabel(xpos,ypos,txt); alert(label); globe.root.appendChild(label); globe.navigate.flyTo(label); } </script>’
+'</body></html>’)
myRef.document.close()
}
[/code]

I thank you all in advance,
Sharat.

to post a comment
JavaScript

12 Comments(s)

Copy linkTweet thisAlerts:
@justinbarneskinJul 31.2009 — [code=php]function textlabel()
{
myRef = window.open('','mywin','left=20,top=20,width=500,height=500,toolbar=1,resizable=0')
docRef = myRef.document.open("text/html","replace");

var AbCdE="<html><head><b> Text Label Properties:</b></br></br> <title>Text Label Properties</title> </head>n<body bgcolor=white onLoad="self.focus()" form=txtlblfrm>nThe position of the object, defined by its coordinates</br> in the 3D world. Can be one of the following: </br> <b> SGCoord3D/ SGCoord2D/ SGPosition </b></br></br></br> <b> X-Position: </b><input type="text" name="lblxpos"/></br></br>n<b> Y-Position: </b><input type="text" name="lblypos"/></br></br>n<b> Label Text: </b><input type="text" name="lbltxt"/></br></br>n<input type="button" value="Submit" onclick="cretxtlbl()" src="global()"><nbsp>'n<input type="button" value="Cancel" onclick="">n<script language="javascript"> function cretxtlbl() { var xpos = document.all["lblxpos"].value; alert(xpos); var ypos = document.all["lblypos"].value; alert(ypos); var txt = document.all["lbltxt"].value; alert(txt); var label = globe.creator.createTextLabel(xpos,ypos,txt); alert(label); globe.root.appendChild(label); globe.navigate.flyTo(label); } </script>n</body></html>n";

myRef.document.write(AbCdE)

myRef.document.close()
}[/code]
Copy linkTweet thisAlerts:
@sharat80authorAug 01.2009 — Thank you for reply Justinbarneskin,

I created a [B]HTML home page[/B] with Horizontal drop down menus with some links. I am loading a 3D window(Globe) in home page by using SGWorld Constructor which is like below in Home page:

[CODE]<script type="text/jscript">
var globe = null;
function init()
{
try
{
globe = new SGWorld("myWorld", onInitFinished);

}
catch(e)
{
alert(e.description);
}

}

function onInitFinished()
{
globe.teCore.ITerraExplorer.Load("C:\Atlanta-ga-base.fly");

}
</script>[/CODE]


I am calling [B]JavaScript Functions(.js page)[/B] from home page for the menu items where [B]globe[/B] Variable is accepted statically for other functions in [B]js page[/B]. I would like to create a [B]dynamic html page from Java Scripting[/B] which should run when calling from [B]home page[/B] and I tried as the above coz my [B]API[/B] is completely on [B]JavaScript[/B] for customization.

I tried coding [B]HTML variable[/B] and [B]myRef.document.write(AbCdE);[/B] but its saying [B]"globe is undefined"[/B] even by [B]declaring[/B] it again. I got fed up past 3 days to fix this [B]error[/B]. Any ideas for solving my requirement [B](dynamic html page from Java Scripting)[/B] will be very helpful to me.

Thanking you,

Sharat.
Copy linkTweet thisAlerts:
@justinbarneskinAug 02.2009 — If you open a window it becomes a child of the opener.

Refer to variables like this-

var globe= opener.globe
Copy linkTweet thisAlerts:
@sharat80authorAug 03.2009 — Thank you for reply justinbarneskin,

I could able to pass globe variable using [B]opener.globe[/B] but still am hanging up, please find the below highlighted code with few changes in scripting variable declaration and respective errors I faced for changes done:

[CODE]
function textlabel()
{
myRef = window.open('','mywin','left=20,top=20,width=500,height=500,toolbar=1,resizable=0')
docRef = myRef.document.open("text/html","replace");
var globe = null;
opener.globe = new SGWorld();
[B] myRef.document.write('<html><head><b> Text Label Properties:</b></br></br> <title>Text Label Properties</title> <script language="javascript"> function cretxtlbl() { var xpos = document.all["lblxpos"].value; alert(xpos); var ypos = document.all["lblypos"].value; alert(ypos); var txt = document.all["lbltxt"].value; alert(txt); var label = opener.globe.creator.createTextLabel(new SGCoord3D(xpos, ypos, 0),txt); alert(label); opener.globe.root.appendChild(label); opener.globe.navigate.flyTo(label); } </script> </head>'[/B]
+'<body bgcolor=white onLoad="self.focus()" form=txtlblfrm>'
+'The position of the object, defined by its coordinates</br> in the 3D world. Can be one of the following: </br> <b> SGCoord3D/ SGCoord2D/ SGPosition </b></br></br></br> <b> X-Position: </b><input type="text" name="lblxpos"/></br></br>'

+'<b> Y-Position: </b><input type="text" name="lblypos"/></br></br>'
+'<b> Label Text: </b><input type="text" name="lbltxt"/></br></br>'
+'<input type="button" value="Submit" onclick="cretxtlbl()">'
+'<input type="button" value="Cancel" onclick="">'
+'</body></html>')
myRef.document.close();

}
[/CODE]


For the below declaration the browser is prompting me error [B]"SGCoord3D is undefined"[/B]
[CODE]
var label = opener.globe.creator.createTextLabel(new SGCoord3D(xpos, ypos, 0),txt);
[/CODE]


For the below declaration browser is prompting me error [B]"object expected"[/B]
[CODE]
var label = opener.globe.creator.createTextLabel(new (opener.SGCoord3D(xpos, ypos, 0)),txt);
[/CODE]


By taking the globe variable after opening the window, browser is prompting me error [B]"Opener is null or not an object"[/B]
[CODE]
opener.globe = new SGWorld();
[/CODE]


I hope you understand my requirement. Fixing the above errors will give me expected result. Can you please help me out for resolving these errors.

Thanks & Regards,

Sharat.
Copy linkTweet thisAlerts:
@justinbarneskinAug 03.2009 — Yes, ts a bit lost. However you are on right track.

It might be that you are trying to recreate the variable on the opener from the child,

if the globe variable must be dynamic and changing, you should write the function in myRef window too.
Copy linkTweet thisAlerts:
@sharat80authorAug 04.2009 — Thanks for reply mate,

I tried in many ways but couldn't able to get the globe object in scripting after [B]window.open()...[/B]. I tried in different ways most of the times am getting [B]error [/B] [B]"SGCoord3D is undefined"[/B] or [B]object expected[/B]. Could you please tell me how to include the same function in [B]myRef window[/B] for [B]globe to be dynamic[/B]? or It will be very helpful to me if you provide some sample code which can perform the above requirement...

Thank you in advance,

Sharat
Copy linkTweet thisAlerts:
@justinbarneskinAug 04.2009 — Sorry, cannot help. I am lost when I don't savvy <B>.creator</B>
Copy linkTweet thisAlerts:
@justinbarneskinAug 04.2009 — [B].creator[/B] ?
Copy linkTweet thisAlerts:
@sharat80authorAug 05.2009 — All the methods are like SGWorld.[B]creator[/B] (createPolyline, createTextLabel, createPolygon...). SGWorld is accepted [B]statically[/B] on the [B].js Page[/B] for all the[B] methods.[/B] Any ideas for creating a [B]HTML Page[/B] from [B]JavaScripting[/B] for giving input dynamically.
Copy linkTweet thisAlerts:
@justinbarneskinAug 05.2009 — document.write the entire HTML. The tricky part is to escape the script tags.

There are some tools on the internet that can help to make it easy, just paste the code in a textarea and the author returns like what I gave in my first reply. When you find the tool, you'll want to save the source code of it.
Copy linkTweet thisAlerts:
@sharat80authorAug 06.2009 — Thanks for reply mate,

I tried the below code for [B]escaping the scripts tags[/B]. The complete script is escaped with logic in for getting output and prompting for object.

[CODE]
......
......
//<SCR'+'IPT language="javascript">
function cretxtlbl()
{
var xpos = document.all["lblxpos"].value;
alert(xpos);
var ypos = document.all["lblypos"].value;
alert(ypos);
var txt = document.all["lbltxt"].value;
alert(txt);
var label = opener.globe.creator.createTextLabel(new SGCoord3D(xpos, ypos),txt);
alert(label);
opener.globe.root.appendChild(label);
opener.globe.navigate.flyTo(label);
}
</SCR'+'IPT>n
</body>
</html>n";
[/CODE]
Copy linkTweet thisAlerts:
@sharat80authorAug 12.2009 — Thank you for all replies given to me. I used frames concept and could get the required output for the project am with.
×

Success!

Help @sharat80 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 6.13,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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