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?

<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

Perfect gumape, thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.