1. This website uses cookies. By continuing to use this website you are giving consent to cookies being used.
    For information on cookies and how you can disable them visit our Cookie Usage page.
    Dismiss Notice

JavaScript problem on javascript onclick event

Discussion in 'Web Development' started by komrad, Oct 31, 2008.

  1. komrad

    komrad Banned

    Hello all,

    I have this code in an iframe

    <FORM><INPUT TYPE="BUTTON" VALUE="Go Back"
    ONCLICK="history.go(-1)"></FORM>

    it works fine but i need it to taget another iframe on the page and change that iframe and go back in its own iframe

    Thanks in advance.
     
  2. ishkey

    ishkey Moderator, Logos, Sports Crests Staff Member Verified Member

    history - will only take you back from where you came from.
    just change the code to suit your needs.
    this will take you to the iframe you specify.
    If you want it as a button, then use the form method.
    Code:
     
    <a href="[URL="http://www.totheiframe.com/"]http://www.totheiframe.com[/URL]"
     onMouseOver="window.status='Back to The Iframe You Go'; 
     return true">Go Back</a>
    
    I do not understand part 2 (change that iframe) and 3 (go back in its own iframe) of your question.
    1 out of 3 is a start.
     
  3. MH Vishal

    MH Vishal New Member

    Thanks so much. It saved my bacon. I've been beating my head against this wall for a good part of this last week and thanks to the info I got here, I can now move on to something more productive and enjoyable.

    The best solution for me was to insert
    if (window.event) event.returnValue = false;
    just before the "return false; "statement.

    I understand the point you made about being reluctant to use browser specific code such as returnvalue, and I agree with that as a general principle. However, I think browser specific code is exactly the right and appropriate response to browser specific bugs.
     
  4. Osman

    Osman Member

    if you give an iframe a name it becomes easy to target it

    for example

    <iframe id="if1" name="frame1" src="iframe1/index.html" frameborder=0></iframe>
    alert(document.getElementById('if1').src) would give you 'iframe1/index.html'
    <iframe id="if2" name="frame2" src="iframe2/index.html" frameborder=0></iframe>
    alert(document.getElementById('if2').src) would give you 'iframe2/index.html'

    <a href="http://www.google.com" target="frame1">Google in frame 1</a>
    <a href="http://www.yahoo.com" target="frame2">Yahoo! in frame 2</a>

    Click these two links,
    alert(document.getElementById('if1').src) would give you 'http://www.google.com'
    alert(document.getElementById('if2').src) would give you 'http://www.yahoo.com'

    similarly, <a href="history.go(-1)" target=frame1,frame2>Step back in history</a>
    should go back in the iframes you desire.
     
  5. maryjohn

    maryjohn New Member

    Hey dear..

    My advise to u just u should change some code what ever u write,
    just put action in the form tag like

    <form action=".. ">
    ..
    ..
    ..
    </form>

    just try it ;)