Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 21st, 2005, 07:22 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default opening external links in a new window.

I will explain my requirement.

I have pages which contain links to other parts of the site or to pages of other sites (external links).

I want to detect the click of the external links and to open it on a new window. The links to other pages of same site should be opened in the same window. But links to pages of other sites should be opened in another window.

This is a content managed site and hence, I have no control on the links put on the site. So, I cannot use the target option of links.

Can this be done with JavaScript ?

Thanks.
  #2 (permalink)  
Old February 21st, 2005, 11:12 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Madhukp!!
You can do this by two ways,may be others also :)
1) Ur asp/php code contains href tag with onclick() event for every href tag,using script,well i don't prefer this technique.In this case
<a href="sd.html" onclick="myfun(this);return false;">adas</a>
<a href="sd1.html" onclick="myfun(this);return false;">adas1</a>
<a href="sd2.html" onclick="myfun(this);return false;">adas2</a>
<a href="sd3.html" onclick="myfun(this);return false;">adas3</a>
<a href="sd4.html" onclick="myfun(this);return false;">adas4</a>


2) I like to use Dom :)

<a href="sd.html">adas</a>
<a href="sd1.html">adas1</a>
<a href="sd2.html">adas2</a>
<a href="sd3.html">adas3</a>
<a href="sd4.html">adas4</a>
<script>
 obj=document.getElementsByTagName('a')
for(i=0;i<obj.length;i++)
{
 obj[i].onclick=function(){myfun(this);return false;};
}
function myfun(obj)
{
alert(obj.href) //this will be the href
chk_domain=obj.href
isurdomain="no" //you must provide it,and check as per ur requirement
if(chk_domain==isurdomain)
 { alert("from ur domain")
   document.location.href=obj.href}
else
 { alert("open new window")
  window.open(obj.href,"","height=500,width=800")
}

}
</script>

Hope this will help you


Cheers :)

vinod
  #3 (permalink)  
Old February 22nd, 2005, 01:04 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

This wouldn't answer your question ... Just chk this usability article http://www.sitepoint.com/article/bew...nks-new-window

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
  #4 (permalink)  
Old February 22nd, 2005, 01:11 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

Thanks a lot vinod. This is exactly what I want.

cheers,
Madhu
  #5 (permalink)  
Old February 23rd, 2005, 02:27 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Madhu !!
Thanks you too,since this makes me to do R&D ,that i like the most.


Cheers :)

vinod


Similar Threads
Thread Thread Starter Forum Replies Last Post
External Multimedia Links bcogney XML 1 February 26th, 2007 10:28 PM
Close Parent window on opening child window pkdev Javascript How-To 8 April 11th, 2004 12:06 PM
Opening file external kaivanrijswijk VBScript 0 March 29th, 2004 05:43 PM
Removing external links in Excel tcarnahan Excel VBA 9 February 22nd, 2004 07:21 AM
Updating external links Justine Access VBA 3 January 14th, 2004 05:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.