?
Solved

For jerrith or other people changing href links in javascript links

Posted on 2002-07-17
15
Medium Priority
?
260 Views
Last Modified: 2013-12-18
jerrith,
in previous question qid=20305006,you gave me a solution in href.
"[" +
    @Implode("<a href=\"" + urls + "\">" + choices + "</A>"; "<BR>") + "</DIV>"
    + "]")
then I ask you how can I do the same in javascript
you gave me the way of work for it but I can't figure it out, how it works
To solve this problem, you'd have to change the popup-menu so that there are no <A HREF=..."> tags created, but a JavaScript function is called to open the url.

To this function, you would pass two parameters : the url to open and the target the url should be opened in.

This function could look something like this :
function openURL(url, target)
  {
  if (target=='_blank')
     {
     window.open(url, "", "");
     }
  else
     {
     location.href=url;
     }
  }
The problem I've is that you have an array and not a simple link.

Can you help me, one more time ?
Thanks
0
Comment
Question by:magnex
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 2
15 Comments
 
LVL 10

Expert Comment

by:zvonko
ID: 7161711
I assume JM want to say this:
choices:=@DbLookup( "":"NoCache" ; "":""; "Menu Structure"; "Documentation"; 2);
urls:=@DbLookup( "":"NoCache" ; "":""; "Menu Structure"; "Documentation"; 3);
"[<DIV CLASS=\"MenuTitle\"  onMouseOver=\"showMenu(\'Documentation\');\">Documentation</DIV><DIV ID=\"Documentation\" CLASS=\"MenuItems\">" +
@If(@IsError(choices);
    "No documents available</DIV>]";
    @Implode("<a href=# onClick=\"openURL(\'"+ urls+"\',\'_blank\')\">"+choices+"</A>";"<BR>")+"</DIV>]")

Instead of _blank target place the name of your frame or the _new target.


Cheers,
zvonko

0
 
LVL 10

Expert Comment

by:zvonko
ID: 7161732
Sorry magnex,

ignore my upper comment. It has nothing to do with your requirement.

Only idea I have is to change the <A> tags to inner <DIV>s, like this:
@Implode("<div onClick=\"openURL(\'"+ urls+"\',\'_blank\')\">"+choices+"</div>";"<BR>")+"</DIV>]")

But this all is not tested by me.

Sorry.


0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
ID: 7161894
If the only thing you want to do is to be able to open a new window or link inside the current frameset, then this is allready in the formula as is.

I'll explain further:

choices:=@DbLookup( "":"NoCache" ; "":""; "Menu Structure"; "Documentation"; 2);
urls:=@DbLookup( "":"NoCache" ; "":""; "Menu Structure"; "Documentation"; 3);
targets:=@DbLookup( "":"NoCache" ; "":""; "Menu Structure"; "Documentation"; 4);
"[<DIV CLASS=\"MenuTitle\"  onMouseOver=\"showMenu(\'Documentation\');\">Documentation</DIV><DIV ID=\"Documentation\" CLASS=\"MenuItems\">]" +
@If(@IsError(choices);
     "No documents available";
     "[" +
     @Implode("<a href=\"" + urls + "\" target=\"" + targets + "\">" + choices + "</A>"; "<BR>") + "</DIV>"
     + "]")

choices calculates the description texts for the menu
urls calculates the url-links to link to the related documents
targets calculates the target where the links are to be opened

So if you put in your menu item document as target _blank a new window will open, if you put the name of an existing frame the document will be opened in that frame.
To open in the current frame, enter _self, to open in the current window, but not inside one of the frames enter _top.

An overview:

_blank : opens a new window
_top : opens in the same window, but outside of frames
_self : opens in the current frame
nameOfFrame : opens in the frame called 'nameOfFrame'

I hope this is a bit clear, if not just let me know.

Regards,
JM
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:magnex
ID: 7164090
jerrith,

My question was to open a new window by using a javascript link and not and href link.
Because, I don't want a menu bar etc ...
And also if you open a new window using href and you do  a window close, he always ask you a confirmation.

 @Implode("<a href=\"" + urls + "\" target=\"" + targets + "\">" + choices + "</A>"; "<BR>") + "</DIV>"
can it be changed to a javascript link

Like above(the question), you can see that you gave me the way of work, but I've problems to make it work
function openURL(url, target)
 {
 if (target=='_blank')
    {
    window.open(url, "", "");
    }
 else
    {
    location.href=url;
    }


Thanks for your time,
Magnex
0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
ID: 7164102
Yes, this can be done.
My test server is up and running again as of today, so I'll have a crack at it. TTYL
0
 
LVL 8

Accepted Solution

by:
Jean Marie Geeraerts earned 400 total points
ID: 7164139
Okay here it is.
Remember in the sample application I had a subform with the menubar.
On this subform add the following function in the JS Header:
// open an URL depending on the target in the current frame or a new window
function openURL(url, target)
     {
     if (target=='_blank')
          window.open(url, "", "")
     else
          location.href=url;
     }

Then change the formula for the menuItems to the following:
choices:=@DbLookup( "":"NoCache" ; "":""; "Menu Structure"; "Documentation"; 2);
urls:=@DbLookup( "":"NoCache" ; "":""; "Menu Structure"; "Documentation"; 3);
targets:=@DbLookup( "":"NoCache" ; "":""; "Menu Structure"; "Documentation"; 4);
"[<DIV CLASS=\"MenuTitle\"  onMouseOver=\"showMenu(\'Documentation\');\">Documentation</DIV><DIV ID=\"Documentation\" CLASS=\"MenuItems\">]" +
@If(@IsError(choices);
     "No documents available";
     "[" +
     @Implode("<A onClick=\"openURL('" + urls + "', '" + target + "'); return false;\" href=\"\">" + choices + "</A>"; "<BR>") + "</DIV>"
     + "]")

The @Implode function will compute the following HTML-code:
<A onClick="openURL('http://urlToOpen.com', '_blank'); return false;" href="">Menu choice description</A><BR>
for every menu item.

This way the JavaScript function openURL is called with the parameters needed to open the URL in the current or a new window.
0
 

Author Comment

by:magnex
ID: 7164400
Again, thanks for the help
It works perfect
Only window.close() works not in my frameset.
I've a framseset with two frames a left one and a right one, in ly right one I've a with javascript code window.close(), but when I click on it, it stays open, probabbly because I'm using a frameset.
And that it's probabbly the reason that he doesn't close my IE window

But, thanks for your time and your help.
0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
ID: 7164500
Yes, window.close will only work for a newly opened window.
In all other occassion window.close will ask for a confirmation.
You should however be able to close a window even if you're using a frameset. (after confirming the action that is)
0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
ID: 7164506
What do you want to achieve with the window.close? Close the window completely or go back to another page?
The first one should work, the second : for that use location.href="url_to_go_to" for example.

Glad to have been of help.
0
 

Author Comment

by:magnex
ID: 7164522
I will close the window completely.
But he does nothing
He don't ask me for a confirmation
He just do nothing
0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
ID: 7164535
Hm, how do you perform this window.close? From an action button or action hotspot?
Have you tried to put an alert("1"); before and an alert("2") after your window.close() statement to see if the error isn't before the window.close statement is reached? (This of course is only necessary if there's a whole script to be executed and not just the window.close)
0
 

Author Comment

by:magnex
ID: 7171285
I just have an action button with one rule window.close()
also the other commands like history.back() don't work.
If I write down and alert before and after the function, he let me see the alerts but he don't close the window or go back to the previous page ?

Any suggestions ?
0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
ID: 7171315
history.back() will never work in a new window, since in the new window there is no previous url to return to.
What browser are you using?
Because normally if you open a new window using window.open, all you need to have in an action button is the line window.close() to close the window, no questions asked.
This would be normal behaviour.
0
 

Author Comment

by:magnex
ID: 7171670
I use IE6
All I have is line window.close()
may it's a problem of IE
I also have the problem that if I embed a view in a page, and set the embedded view option height to fit window that he only shows 40rows, if I specify the height then he let me see all the documents, this problem is only forIE6.
The problem with window.close is in all the versions of IE
0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
ID: 7173655
Strange, I use IE5.5 over here and I don't have the problem with window.close()
As long as I opened the window with window.open I can close the newly opened window with window.close().

It might be an IE6 problem. Who knows...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question