0

I have a script working for me which loads content into an iframe on my index page based on a url query string. for example: mysite.com/index.php?two.php loads "two.php" into the iframe, heres what i have:

<script type="text/javascript">
function loadIframe()
{
var urlStr;
urlStr = location.search.slice(1);
window.frames.myiframename.location = urlStr;
}
</script>

Next, I call the function in the body onload:

<body onLoad="loadIframe()">

Only problem is when navigating to "www.mysite.com" the onload function loops and loads subsequent index pages into each others iframes. How can I set the default frame src to "home.php" and tell my javascript function only to execute if there is a query in the url string?

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by revata
0
<head>
    <script>
		function loadIframe () {
			var urlStr;
			urlStr = location.search.slice(1);
			if (urlStr.length == 0) {
				urlStr = "home.php";
			}
			window.frames.myiframename.location = urlStr;
		}
    </script>
</head>
<body onload="loadIframe ()">
</body>

Related links:
search property,
slice method,
String object

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.