Forum Moderators: open

Message Too Old, No Replies

Complex javascript problem

Using an agent to specify a new window from a frame

         

petersmall

9:49 am on Sep 24, 2003 (gmt 0)

10+ Year Member



The system I'm working on calls upon agents in the form of javascript documents (SRCs) to dynamically write link instructions within a frame.

The instructions are written in the form:

document.write([an anchor link from an array in the agent file]);

The array element in the agent file would be of the form:
"<a href = 'http://www.example.com/'>http://www.example.com/</a>"

This works fine. When the link is clicked on, the URL specified opens up in the frame. However, what I want to do is to have the instruction so that the URL opens up in a new window, and leaves the frame window unchanged.

I can open up the URL in a new window by changing the array element to the form:
"<a href = 'javascript:window.open(\"http://www.example.com/");'>http://www.example.com/</a>"
(This is using an escape char \")

This opens the URL in a new window when clicked but it replaces the content of the frame with:
"[object Window]"

What can I do to keep the URL in the frame unchanged when the new window is opened?

peter

[edited by: tedster at 2:50 pm (utc) on Sep. 24, 2003]

Zaphod Beeblebrox

10:26 am on Sep 24, 2003 (gmt 0)

10+ Year Member



First of all, edit out the domain name. It's against TOS.

Second, use <a href='www.mydomain.com' target='_blank'>, that will open the link a new window.

petersmall

11:36 am on Sep 24, 2003 (gmt 0)

10+ Year Member



Thanks Peter,

That target='blank' solution worked perfectly

That solution hadn't occured to me.

peter

MonkeeSage

8:16 pm on Sep 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"<a href=\"http://www.example.com/\" onclick=\"void(window.open(this.href, '', '')); return false;\">http://www.example.com/</a>"

Use a real href so SEs see it.
Use the

this
object to refer to the value of href in the window.open() method.
Use void() to null the window object returned by the window.open() method.
Use
return false
to cancel the propigation of the event so that the browser doesn't try to load href in the calling window.

HTH
Jordan