简体   繁体   中英

Automatic redirect issue in iframe

I have an iframe links within an html page as shown below:

    <TABLE border="0" width="900">
    <tr valign="top">
    <td width="300" ALIGN=center>
            <div class="item_list">
            <a href="http://www.skiholidayextras.com?   affiliate_id=172&amp;submit_to=http://www.skihautesavoie.fr/results-lift-pass.html" target="_blank">link</a>
            </div>
    </td>
    <td width="300" ALIGN=center>
            <div class="item_list">
            <iframe src = 'http://www.flipkart.com/affiliate/displayWidget?affrid=WRID-137232779171598318' frameborder = 0, height=250, width = 300 > </iframe></a><br>
            </div>
    </td>
    <td width="300" ALIGN=center>
            <div class="item_list">
            <iframe src = 'http://www.flipkart.com/affiliate/displayWidget?affrid=WRID-137232785207215857' frameborder = 0, height=250, width = 300 > </iframe>


Now when i click within an iframe link , it open the link, but when i click back, it automatically redirect me to that iframe link. Can anyone suggest me what's the problem i'am having?

In your case I would implement my own controls for each iframe. Delegate this work to some buttons on your page instead:

<div id="view_iframe">
    <iframe id="viewer" name="viewer" width="100%" height="600" src="some.html">
         <p>Your browser does not support iframes.</p>
    </iframe>
    <input type="button" id="back" class="button" onClick="viewer.history.back();" value="<<" />
    <input type="button" id="frwrd" class="button" onClick="viewer.history.forward();" value=">>" />
</div>

note - viewer is iframe id

note that both buttons, are positioned absolutely to align with iframe on page resize.

anyway, here are what the iframe controls for this:

// For an iframe's window
iframe.contentWindow.history.back(); 
iframe.contentWindow.history.forward();

or

iframe.contentWindow.history.go(-1); // back
iframe.contentWindow.history.go(1);  // forward

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM