Solved

For jerrith or other people changing href links in javascript links

Posted on 2002-07-17
15
244 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
  • 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
 

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 100 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now