Solved

For jerrith or other people changing href links in javascript links

Posted on 2002-07-17
15
243 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

771 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

11 Experts available now in Live!

Get 1:1 Help Now