Forum Moderators: open
I want to open the external link of pageA.htm in the main frame of pageB.htm
Thanks for any suggestion
Hanyaz
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
<title>Untitled</title>
</head>
<body>
<a href="http://www.example.com">example</a>
<script type="text/javascript">
window.onload = function () {
var elList = document.getElementsByTagName('a');
var i;
for (i = 0; i < elList.length; i++) {
elList[i].href = "pageB.htm?s=" + encodeURI(elList[i].href);
}
};
</script>
</body>
</html>
In that example, I created regular links and then used JavaScript to change them to support my framed page (since JavaScript is going to be required on my frameset page, I want to allow the links to work for those with JavaScript disabled). Alternatively, I could use a server side language like PHP or ASP (as DrDoc hinted at), which would be a better solution.
Next, your pageB.htm:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
<title>Untitled</title>
<script type="text/javascript">
window.onload = function () {
var url = location.search;
var i, main = document.getElementById('main');
url = url.replace('?',''); // Strip leading ?
url = url.split('&'); // Parse each key/value pair
// [s=..., x=..., y=...]
for (i = 0; i < url.length; i++) {
url[i] = url[i].split('='); // Split keys and values
url[url[i][0]] = url[i][1]; // Assign the value as a property of url
}
main.src = url['s'];
};
</script>
</head>
<frameset rows="25%, 75%">
<frame id="header">
<frame id="main">
</frameset>
</html>
My parsing of the URL was a little quick and dirty... you might want to perform more validation checks.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
<title>Untitled</title>
<script type="text/javascript">
window.onload = function () {
var url = location.search;
var i, main = document.getElementById('main');
url = url.replace('?',''); // Strip leading ?
url = url.split('&'); // Parse each key/value pair
// [s=..., x=..., y=...]
for (i = 0; i < url.length; i++) {
url[i] = url[i].split('='); // Split keys and values
url[url[i][0]] = url[i][1]; // Assign the value as a property of url
}
alert('Setting the main.src value to:\n' + url['s']);
main.src = url['s'];
alert('Done');
};
</script>
</head>
<frameset rows="25%, 75%">
<frame id="header">
<frame id="main">
</frameset>
</html>