By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

open links in parent window ?

P: 77
Hi Im looking for a way to open all links (in a child window) in the parent window
instead. I want this to happen Automatically because links in my child are called from the parent but I cannot alter link targets.
<base target="x">(in child head tags) dont work, though some will launch a new window.

I found this code idea that does work (see below) but I have no way of assigning the 'loadinparent' attribute to my childwindow links. Can I do that with javascript?
e.g.

if getelementbytagname==(a)
then (a) = ('this attribute')
}

what works (head of child)

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function loadinparent(url){
  3.     self.opener.location = url;
  4.  
  5.     }
  6.  
  7. </SCRIPT>
link in child must be

Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:loadinparent('http://www.google.com.au', true);">Google</a>
  2.  
Nov 4 '07 #1
Share this Question
Share on Google+
6 Replies


gits
Expert Mod 5K+
P: 5,390
hi ...

you may use a function like the following:

Expand|Select|Wrap|Line Numbers
  1. function adapt_links() {
  2.     var links = document.getElementsByTagName('a');
  3.  
  4.     for (var i = 0; i < links.length; i++) {
  5.         var link = links[i];
  6.  
  7.         link.href = 'javascript:loadinparent("' + link.href + ', true")';
  8.     }
  9. }
call that onload of your popup-page ...

kind regards
Nov 4 '07 #2

P: 77
Thankyou So much freind, I've been struggling with this for days, I was unable to work out how to affect link elements.
You've been a great Help, I really Appreciate it!
Cheers from Australia :)
Nov 4 '07 #3

gits
Expert Mod 5K+
P: 5,390
hi ... no problem :) in case you have more questions, post back to the forum anytime ...

kind regards
Nov 4 '07 #4

P: 77
Actually I do have another request :D this one may be a little difficult?

I have discovered that guest cannot veiw active topics on my site (though they can search manually and read them) . Presently Im using a somewhat dodgy
code to extract and display links from the active topics page for members
(see below) and using it in combo with the adapt url code you helped with above.
reason im doing it that way is that the extraction code is very slow, because it calls the links every pageload, so to speed the site up im using the code above , with the slow code below in a new window, so users dont suffer slow pageloads (they need open the popup only once).
Now what I want to do is use another code (2nd below) with some modification,
to allow guests a similar menu of active topics links (since the first code below is somehow blocked for them)
This code (2nd below) will extract links from that specific page into another specific page but I want to define/host the page so I can use the adapt links/load in parent code above[if thats possible]
unless you can find a better way to extract and display links than the ( first code below) ???
I realise this is a very complicated and odd request that may not be possible, but it was just the (2nd code below) that gave me the idea.
Thanks in advance!
cheers from Australia!

Expand|Select|Wrap|Line Numbers
  1. <table width="83%" td align="center" cellspacing="0" id="submenu">
  2. <tr>
  3. <td align=left>
  4.  
  5. <table width="100%" height="40px" border="0" cellspacing="0" cellpadding="0">
  6. <tr>
  7. <td class="row1" width="100%" height="40px"style="text-align:center"><marquee behavior=scroll direction=up scrollamount=4 onmouseover=this.stop() onmouseout=this.start() id="activetomar"></marquee></td>
  8. </font>
  9. </td></tr></table></td></tr></table>
  10. <script language="javascript" type="text/javascript">
  11. <!--
  12. if(self.location.href.match('http://herproom.5.forumer.com/index.php?&act=Search&CODE=getactive')){
  13. actm = document.getElementById('activetomar');
  14. actm.innerHTML += "<table class='tableborder'>Active Topics Removed</table>"
  15. }
  16. else {
  17. document.write("<iframe name='activetopmarq' src='http://herproom.5.forumer.com/index.php?&act=Search&CODE=getactive' style='display:none;' onload='latemarqHarvest()'></iframe>");
  18. //-->
  19. function latemarqHarvest()
  20. {
  21. martab = window.frames["activetopmarq"].document.getElementsByTagName("table");
  22. for(var i = 0; i < martab.length; i++){
  23. if(martab[i].className == "tablebasic" && martab[i].parentNode.className == "tableborder"){
  24. tabdiv = martab[i].innerHTML
  25. goingNav(tabdiv)
  26. }
  27. }
  28. }
  29. function goingNav(tabdiv)
  30. {
  31. actm = document.getElementById('activetomar');
  32. actm.innerHTML += "<table class='tableborder'>" + tabdiv + "</table>";
  33. }
  34. }
  35. //-->
  36. </script>
Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript1.2">
  2. function extractlinks(){
  3. var links=document.all.tags("A")
  4. var total=links.length
  5. var win2=window.open("","","menubar,scrollbars")
  6. win2.document.writeln('<link rel="stylesheet" href="http://www.fileden.com/files/2006/9/25/238265/default%20skin.txt" type="text/css">')
  7. win2.document.write("<h2>Total Links="+total+"</h2><br>")
  8. for (i=0;i<total-1;i++){
  9. win2.document.write(links[i].outerHTML+"<br>")
  10.  
  11. }
  12. }
  13. //-->
  14. </script>
  15. <button onClick="extractlinks()">Extract Links</button>
  16.  
  17.  
Nov 5 '07 #5

P: 77
Sorry, Ignore the last post, I found a setting Id overlooked to allow guest to see the original code. LOL

Thanks again so much for your help on this issue. This topic is Resolved!
Nov 6 '07 #6

gits
Expert Mod 5K+
P: 5,390
hi ...

glad to hear that :) ... post back to the forum anytime you have more questions ...

kind regards
Nov 6 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.