...

View Full Version : target window.location.href to iframe on new page



ScriptKitten
06-15-2010, 06:13 PM
I know next to nothing about javascript and I don't even know if this is possible. I need to target window.location.href to an iframe on a different page.

So, right now, the piece of the code that redirects the browser looks like this:


window.location.href='http://www.somewhere.com/';

Works great, brings it up in the same browser window. So now I need to modify the code so it goes to a different page and brings that page up in a specified iframe.

I hope this makes sense. I really need help. And if it is not possible, I just need to know to abandon all hope.

Philip M
06-15-2010, 06:24 PM
Here you are:-


<iframe id = "myFrame"></iframe>

<script type = "text/javascript">
document.getElementById("myFrame").src = "http://www.google.com";
</script>


Quizmaster: What is 64 divided by eight?
Contestant: Six.

ScriptKitten
06-15-2010, 06:49 PM
ok i can see how that would target it to an iframe on the same page. but I need it to go to an iframe on a different page.

Old Pedant
06-15-2010, 09:21 PM
??? A different page that is loaded into the same window? Or a different page in a different window?

And do you "own" the "different page"? That is, can you modify its code?

ScriptKitten
06-15-2010, 11:56 PM
let me clairfy...

for example...
index.php has a form that when the submit button is clicked, it calls a function which does some stuff and then forwards the user to the next page, results.php.

what I need it to do is...

index.php has a form that when the submit button is clicked, it calls a function which does some stuff and then forwards the user to the next page, template.php with results.php loaded in myframe.

Does that make better sense?

Old Pedant
06-16-2010, 01:06 AM
Okay, then you would be better off using PHP to accomplish this.

Not hard. Simple example. *EXISTING* situation:


-- file: index.php
<form action="results.php" method="post">
<input name="foo">
<input type="submit">
</form>

-- file: results.php
<?php
$foo = $_REQUEST["foo"];
... generate the page ...


*Modified* situation:


-- file: index.php
<form action="template.php" method="post">
<input name="foo">
<input type="submit">
</form>

-- file: template.php:
<?php
$foo = $_REQUEST["foo"];
...
?>
<iframe src="results.php?foo=<?php echo $foo; ?>"></iframe>

-- file: results.php
<?php
$foo = $_REQUEST["foo"];
... generate the page ...



See? Just use your template.php page to pass the info along to the iframe page.

If you use $_REQUEST then it works with either method=post data or with querystring data, so it's a really simple change.

Old Pedant
06-16-2010, 01:08 AM
If you think you *must* have a JavaScript solution, it can be done. But if your "results.php" page needs those <form> fields passed to it, anyway, it would be a much much messier solution.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum