Link to home
Start Free TrialLog in
Avatar of magnex
magnex

asked on

For jerrith or other people changing href links in javascript links

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
Avatar of zvonko
zvonko

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

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.


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
Avatar of magnex

ASKER

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
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
ASKER CERTIFIED SOLUTION
Avatar of Jean Marie Geeraerts
Jean Marie Geeraerts
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of magnex

ASKER

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.
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)
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.
Avatar of magnex

ASKER

I will close the window completely.
But he does nothing
He don't ask me for a confirmation
He just do nothing
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)
Avatar of magnex

ASKER

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 ?
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.
Avatar of magnex

ASKER

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
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...