469,322 Members | 1,615 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,322 developers. It's quick & easy.

targeting frames with javascript

Have pity on me.. i have been doing html, css, javascript squarely over 2 years... and am now doing a family project.. in my project i have decided to use a context menu script, its a menu that pretty much allows for when you right click on a page it shows you different links that the standard right click menu, link here:
http://www.dynamicdrive.com/dynamici...ontextmenu.htm
What it does exactly is opens a new window with the link that you have chosen, on the link that i have given above the demo is in the page, right click anywehre, and you'll see... now.. like is said it opens with a right click,... the problem that i am having is that when a window opens...it opens in a new window... i want it to open in one of my frames, here is the code snippet: (thats the original that i didnt change )


Code:
[HTML]<div id="ie5menu" class="skin0" onMouseover="highlightie5(event)" onMouseout="lowlightie5(event)" onClick="jumptoie5(event)" display:none>
<div class="menuitems" href="http://www.google.com">google</div>
<div class="menuitems" url="http://dynamicdrive.com/new.htm" target="newwin">What's New?</div>
<div class="menuitems" url="http://dynamicdrive.com/hot.htm">What's Hot?</div>
<div class="menuitems" url="http://wsabstract.com/cgi-bin/Ultimate.cgi">Message Forum</div>
<div class="menuitems" url="http://dynamicdrive.com/faqs.htm">FAQs</div>
<div class="menuitems" url="http://dynamicdrive.com/submitscript.htm">Submit</div>
<hr>
<div class="menuitems" url="mailto:dynamicdrive@yahoo.com">Email Us</div>
</div>
[/HTML](main is the name of one of the frames that i am using)
i change the

Code:
[HTML]<div class="menuitems url="http://www.google.com">google</div>[/HTML](which works by the way) to
[HTML]<div class="menuitems url="http://www.google.com" target="main">google</div>[/HTML] (main is a legit name of one of my frames) however that doesnt seem to work the window still launches in a new window. i have even tried to delete the whole <div> </div> and replace it all with [HTML]<a href="http://www.google.com" target="main">gogle</a>[/HTML] but that just breaks the menu altogether,...

one person on a html forum told me that the problem is not in my html code... but in the operating javascript... the menu is not running an external javascript code, however there is an internal javascript functions, but i dont know how to change it to open in a frame, i am posting the body of the document below:



Code:
[HTML]<div id="ie5menu" class="skin0" onMouseover="highlightie5(event)" onMouseout="lowlightie5(event)" onClick="jumptoie5(event)" display:none>
<div class="menuitems" url="http://dynamicdrive.com">Dynamicdrive.com</div>
<div class="menuitems" url="http://dynamicdrive.com/new.htm" target="newwin">What's New?</div>
<div class="menuitems" url="http://dynamicdrive.com/hot.htm">What's Hot?</div>
<div class="menuitems" url="http://wsabstract.com/cgi-bin/Ultimate.cgi">Message Forum</div>
<div class="menuitems" url="http://dynamicdrive.com/faqs.htm">FAQs</div>
<div class="menuitems" url="http://dynamicdrive.com/submitscript.htm">Submit</div>
<hr>
<div class="menuitems" url="mailto:dynamicdrive@yahoo.com">Email Us</div>
</div>
[/HTML]
Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript1.2">
  2.  
  3. //set this variable to 1 if you wish the URLs of the highlighted menu to be displayed in the status bar
  4. var display_url=0
  5.  
  6. var ie5=document.all&&document.getElementById
  7. var ns6=document.getElementById&&!document.all
  8. if (ie5||ns6)
  9. var menuobj=document.getElementById("ie5menu")
  10.  
  11. function showmenuie5(e){
  12. //Find out how close the mouse is to the corner of the window
  13. var rightedge=ie5? document.body.clientWidth-event.clientX : window.innerWidth-e.clientX
  14. var bottomedge=ie5? document.body.clientHeight-event.clientY : window.innerHeight-e.clientY
  15.  
  16. //if the horizontal distance isn't enough to accomodate the width of the context menu
  17. if (rightedge<menuobj.offsetWidth)
  18. //move the horizontal position of the menu to the left by it's width
  19. menuobj.style.left=ie5? document.body.scrollLeft+event.clientX-menuobj.offsetWidth : window.pageXOffset+e.clientX-menuobj.offsetWidth
  20. else
  21. //position the horizontal position of the menu where the mouse was clicked
  22. menuobj.style.left=ie5? document.body.scrollLeft+event.clientX : window.pageXOffset+e.clientX
  23.  
  24. //same concept with the vertical position
  25. if (bottomedge<menuobj.offsetHeight)
  26. menuobj.style.top=ie5? document.body.scrollTop+event.clientY-menuobj.offsetHeight : window.pageYOffset+e.clientY-menuobj.offsetHeight
  27. else
  28. menuobj.style.top=ie5? document.body.scrollTop+event.clientY : window.pageYOffset+e.clientY
  29.  
  30. menuobj.style.visibility="visible"
  31. return false
  32. }
  33.  
  34. function hidemenuie5(e){
  35. menuobj.style.visibility="hidden"
  36. }
  37.  
  38. function highlightie5(e){
  39. var firingobj=ie5? event.srcElement : e.target
  40. if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems"){
  41. if (ns6&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode //up one node
  42. firingobj.style.backgroundColor="highlight"
  43. firingobj.style.color="white"
  44. if (display_url==1)
  45. window.status=event.srcElement.url
  46. }
  47. }
  48.  
  49. function lowlightie5(e){
  50. var firingobj=ie5? event.srcElement : e.target
  51. if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems"){
  52. if (ns6&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode //up one node
  53. firingobj.style.backgroundColor=""
  54. firingobj.style.color="black"
  55. window.status=''
  56. }
  57. }
  58.  
  59. function jumptoie5(e){
  60. var firingobj=ie5? event.srcElement : e.target
  61. if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems"){
  62. if (ns6&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode
  63. if (firingobj.getAttribute("target"))
  64. window.open(firingobj.getAttribute("url"),firingobj.getAttribute("target"))
  65. else
  66. window.location=firingobj.getAttribute("url")
  67. }
  68. }
  69.  
  70. if (ie5||ns6){
  71. menuobj.style.display=''
  72. document.oncontextmenu=showmenuie5
  73. document.onclick=hidemenuie5
  74. }
  75.  
  76. </script> 
  77.  
  78.  
i've figured out its this part


Expand|Select|Wrap|Line Numbers
  1. function jumptoie5(e){
  2. var firingobj=ie5? event.srcElement : e.target
  3. if (firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems"){
  4. if (ns6&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode
  5. if (firingobj.getAttribute("target"))
  6. window.open(firingobj.getAttribute("url"),firingobj.getAttribute("target"))
  7. else
  8. window.location=firingobj.getAttribute("url")
  9. }
  10. }
  11.  
  12.  
i've changed the last line (window.location=firingobj.getAttribute("url")
to the following:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("kirupa").src=firingobj.getAttribute("url");
  2. kirupa.location=firingobj.getAttribute("url")
  3. Kirupa.document.location=firingobj.getAttribute("url")
  4. document.frames[kirupa].location=firingobj.getAttribute("url")
  5. document.frames["kirupa"].location=firingobj.getAttribute("url")
  6.  
...nothing works.. help?
Aug 15 '07 #1
3 2156
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

Your link is broken. See how to access frames here.
Aug 16 '07 #2
yea that dont work... tried all that, im doing javascript int.. meaning i need help changing this line

parent.frames['kirupa'].location.href=firingobj.getAttribute("url");
Aug 16 '07 #3
acoder
16,027 Expert Mod 8TB
Try
Expand|Select|Wrap|Line Numbers
  1. parent.kirupa.location.href=firingobj.getAttribute("url");
PS. changed thread title to remove "HELP?!".
Aug 17 '07 #4

Post your reply

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

Similar topics

1 post views Thread by Frances Valdes | last post: by
10 posts views Thread by Richard Lionheart | last post: by
10 posts views Thread by steve | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.