Saurabh Chaudhary
Saurabh Chaudhary

Reputation: 171

target iframe from different page in php or javascript

I am creating a template demo bar, where people can view my created web themes. User will click preview button on one page and will be able to see theme in iframe in another page. Below is the code for link page

<html>
<head></head>
<body>
<a href="http://site/demobar?theme=http://www.template.com">preview</a>
</body>
</html>

and then on demo page I get the iframe

<iframe src="<?php echo $_GET['theme']; ?>" style="width:100vw; height:100vh;"></iframe>

This works ok, but my problem is in returning url which displays the URL:

http://site/demobar/?theme=http://www.template.com

I want template name instead of template address in URL

http://site/demobar/?theme=themeName

How can I achieve this!!, is there any other alternative with javascript!

Upvotes: 0

Views: 551

Answers (1)

Basic
Basic

Reputation: 26766

First of all, set up an array with possible themes, and pick the appropriate one based on the theme parameter...

<?php 
    $themes = array(
        "theme" => "http://www.theme.com/",
        "othertheme" => "http://www.some-other-theme.com/",
    );
    $themeAddress = $themes[$_GET['theme']];
?>

Next, generate the iframe with reference to the url...

<iframe src="<?php echo $themeAddress; ?>" style="width:100vw; height:100vh;"></iframe>

Then call the url with the appropriate theme name:

http://site/demobar/?theme=othertheme

Upvotes: 1

Related Questions