Forum Moderators: open

Message Too Old, No Replies

Dual Browsing

         

YamiHoshi

2:20 pm on Feb 11, 2010 (gmt 0)

10+ Year Member



I have a problem with Javascript.
I have 2 iFrames, written in HTML.
Therefor, I have to make in Javascript a Back, Forward and Refresh button, and add an Address Bar.
As far as I got, the Back buttons pick the wrong iFrame, and the other buttons, and the Address Bar fully don't work.
The project is Open-Source, so I'll share the code I've created, so far:
<html>
<head>
<title>[b]EDIT: Example[/b]</title>
</head>
<body>
<form>
<input type="button" VALUE="&lt; &lt; &nbsp; Back &nbsp;" id="myIframe" onClick="history.back()">
<input type="button" VALUE="&nbsp; Next &nbsp; &gt; &gt;" id="myIframe" onClick='history.forward()"'>
<input type="button" value="Reload" id="myIframe" onclick="location.reload()">
<input id="myput" type="text">
<input type="button" value="Go" onclick="myIframe.src='document.getElementById('myput').value'';">

<input type="button" VALUE="&lt; &lt; &nbsp; Back &nbsp;" id="yoIframe" onClick="history.back()">
<input type="button" VALUE="&nbsp; Next &nbsp; &gt; &gt;" id="yoIframe" onClick='history.forward()"'>
<input type="button" value="Reload" id="yoIframe" onclick="location.reload()">
<input id="yoput" type="text">
<input type="button" value="Go" onclick="yoIframe.src='document.getElementById('yoput').value'';">
</form>
<br />
<iframe height="95%" width="48%" frameborder="0" src="http://www.example.com/x "frameborder=yes name="myIframe" id="myIframe"></iframe>
<iframe height="95%" width="48%" frameborder="0" src="http://www.example.com" "frameborder=yes name="yoIframe" id="yoIframe"></iframe>
</body>
</html>

Could someone correct me, and say what I've done wrong?

[edited by: Fotiman at 5:33 pm (utc) on Feb 11, 2010]
[edit reason] Examplified URLs, replaced identifying info with Example. [/edit]

rainborick

6:16 pm on Feb 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can't rely on the browser's history system to support content changes in <iframe>s. You'll need to support those functions in your script.

YamiHoshi

6:37 pm on Feb 11, 2010 (gmt 0)

10+ Year Member



And how do I exactly do it?

rainborick

8:52 pm on Feb 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Record the user's selections, and use that record to support <back>, <forward>, and other functions.

I didn't examine your code very carefully before, and I missed a couple of issues you need to deal with. One thing that stands out is that you use the same 'id' attribute value on several of the <input type="button"> tags. 'id' attributes should always have a unique value that identifies the individual tag.

The references in your example that use the 'history' object will all refer to the parent document's history, not the <iframe>s. You'll need to point the onClick values to a function that modifies the src of the individual <iframe> elements, based on the records that your code creates each time the user clicks on one of the buttons. You'll also need to create a pointer value that keeps track of the current setting in the history records for each <iframe>.

In essence, you'll be creating a list/array of URLs that record the values of the src attributes in the <iframe>s - one for each - along with a pointer value to keep track of which URL is currently being displayed in the <iframe>. Then you'll update both the list and the pointer as the user clicks on the buttons that change the content of the <iframe>.

YamiHoshi

9:11 pm on Feb 11, 2010 (gmt 0)

10+ Year Member



Could you give me an example code?
I didn't work with Javascript before, the codes are based on Google Search results.

rainborick

3:08 am on Feb 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm sorry, but I don't have time to write your code for you. If you don't know JavaScript, then you'll be best off simply using regular <frame>s so that almost everything will be done for you automatically.