Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2004, 04:44 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with window.open

I have a frame site that has a nav frame, a title frame and a content frame. I have a hyperlink in my content frame that is as follows:

<a href="javascript:window.open(window.parent.locatio n);">visit</a>

Now it opens up the window and takes the user to the right place with no problem. Here is the issue. The content fram changes after this is clicked. So if I minimize the window that was brought up using the location variable, I see a blank content frame except for the word [object] written on the upper left corner of the window. How do I get it to stay where it was before I clicked it or send it to a specific page?

~Clay

Clay Hess
__________________
Clay Hess
 
Old April 27th, 2004, 04:47 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I think (not sure) that if you add 'return false;' to the window.open call, this doesn't happen.

HTH,

Snib

<><
 
Old April 27th, 2004, 04:56 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So, would I do it like this...?

window.open(window.parent.location,'returnfalse;')

Quote:
quote:Originally posted by Snib
 I think (not sure) that if you add 'return false;' to the window.open call, this doesn't happen.

HTH,

Snib

<><
Clay Hess
 
Old April 27th, 2004, 04:57 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Like this:

<a href="javascript:window.open(window.parent.locatio n,'thewindowname','any_preferences');return false;">

Sorry for not explaining myself better.

HTH,

Snib

<><
 
Old April 27th, 2004, 07:21 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is what I did...and it did not work...

 <a href="javascript:window.open(window.parent.navigat ion);return false;">visit</a>

It rendered the link useless...it did not perform the window.open

Any other thoughts?


Quote:
quote:Originally posted by Snib
 Like this:

<a href="javascript:window.open(window.parent.locatio n,'thewindowname','any_preferences');return false;">

Sorry for not explaining myself better.

HTH,

Snib

<><
Clay Hess
 
Old April 27th, 2004, 07:31 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Try this instead:

<a href=javascript:// onclick=window.open(window.parent.location)>visit</a>

HTH,

Snib

<><
 
Old April 28th, 2004, 08:35 AM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot! It worked perfectly! Now can you explain why? What difference do the forward slashes make? I want to make sure I understand the code. Also, do you know how to make a link like this only show up if there is something in the window.parent.location object? I do not want it to show up if it is empty.

Thanks again for all your help.


Quote:
quote:Originally posted by Snib
 Try this instead:

<a href=javascript:// onclick=window.open(window.parent.location)>visit</a>

HTH,

Snib

<><
Clay Hess
 
Old April 28th, 2004, 08:39 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

The forward slashes are a JavaScript comment like this:

function function1()
{
 dosomething();
 //this is a comment
}

The slashes in the link just make the link empty. Without the href your link wouldn't look like a link, just plain text. The onclick event would still fire when the user clicks, but they wouldn't know to click it if it just looks like plain text. An alternative to this is just putting '#' in the href or 'javascript:;'. All three just make nothing happen.

As to your second question, I have to do some research....

HTH,

Snib

<><
 
Old April 28th, 2004, 08:45 AM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for the explanation. I had tried the # sign originally and could not get it to work. I must have done something wrong, but it is good to know the alternatives. Again...thanks for all your help.

~Clay

Quote:
quote:Originally posted by Snib
 The forward slashes are a JavaScript comment like this:

function function1()
{
dosomething();
//this is a comment
}

The slashes in the link just make the link empty. Without the href your link wouldn't look like a link, just plain text. The onclick event would still fire when the user clicks, but they wouldn't know to click it if it just looks like plain text. An alternative to this is just putting '#' in the href or 'javascript:;'. All three just make nothing happen.

As to your second question, I have to do some research....

HTH,

Snib

<><
Clay Hess
 
Old April 28th, 2004, 11:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Dear Clay:
ur code was missing something
Code:
<a href="[u]javascript:window.open(window.parent.location);</u>">visit</a>
[u]href</u> is a property of linking page Address, but u were using it as an event.
event: is a method that fire at its time such as:
onclick: when u click
onload: when something loads(Page)
onclose: when something closing(Page)
& ...

So u should have onclick as an event to rise it & can NOT use href property instead.
HTH.

Always:),
Hovik Melkomian.





Similar Threads
Thread Thread Starter Forum Replies Last Post
open window problem geogomez Javascript How-To 2 December 9th, 2005 05:23 AM
Open New Window b_camp Classic ASP Basics 2 May 12th, 2005 01:19 AM
window.open() problem liorlankri ASP.NET 1.x and 2.0 Application Design 3 December 22nd, 2004 09:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.