target iframe from different page in php or javascript - 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>
preview
</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!

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

Related

Change html code in php when I have many same php files

I have question if is it even possible.
I have contact.php home.php and porfolio.php .
In every single site I have exacly same header (include "header.php") and only what I need is change one h1. I mean on every site have different title of h1. Is there any possible way, to change on every site html code differently ?
Like every site have same header.php but every time different h1..
Or should I make like "one half of code.php" .. CHANGEABLE CONTENT .. "second half of code.php.
Or should I do it in javascript ? like onload function and if site is contact.php then change h1.innerHTML on "".. ?
<body>
<?php include "./components/header.php"; ?>
</body>
I'm pretty sure someone on stackoverflow have answered a similar question but you can do something like
<body>
<?php
$h1Content = "put your desired h1 content here";
include "./components/header.php";
?>
</body>
Then in your header.php, do
<h1><?php echo $h1Content ?></h1>
You can also use an isset to check or set a default value
<h1><?php echo isset($h1Content)? $h1Content : 'Default Value' ?></h1>
you can achieve this easily. All you have to do is to assign header value to an variable and then use that variable in your header file.
//header.php file
<h1><?php echo $mainHeader; ?></h1>
and then before you inject the header you have to init that value on each site
<?php $mainHeader = 'Hello world'; ?>
<body>
<?php include "./components/header.php"; ?>
</body>

Jquery, wordpress and ACF

I have a wordpress site and I use ACF. (https://www.advancedcustomfields.com/).
I have several articles on my home page with a unique image for each article.
This is what I use for my article's images :
<div class="image_cover_home" style="background-image:url(<?php echo get_field('image_cover', $value->ID)['url'] ?>)" >
My php echo get_field works with this code : I have different image, one for each article :
I tried to use a parallax effect on these images, so I use this script :
http://pixelcog.github.io/parallax.js/
$('.image_cover_home').parallax({
imageSrc: '<?php echo get_field('image_cover', $value->ID)['url'] ?>',
naturalWidth: 400,
naturalHeight: 200,
speed:0.8
});
The problem is when I put my php echo field on this jquery script, it doesn't recognize the ID of my images. So I have the same images for each article...
Why ?
Check ACF setting for return type. As i remember return type for image field can be image object or url.
The usage instructions say that you can apply the effect via data attributes:
Add data-parallax="scroll" to the element you want to use, and
specify an image with data-image-src="/path/to/image.jpg"
Example:
<div class="parallax-window" data-parallax="scroll" data-image-src="/path/to/image.jpg"></div>
So instead of manually calling the plugin for each image, use the data attribute:
data-image-src="<?php echo get_field('image_cover', $value->ID)['url'] ?>"

Passing $data variable to iframe from controller in CodeIgniter

I want to display a page in iframe. This page contains email contents since I am building an inbuilt email system. But the CSS of the email contents are overriding my CSS styles. Now this page gets some data from $data variable which I Pass through controller.
To avoid getting my CSS style issues I am thinking of displaying that page in an iframe. (If anybody has any other solutions, welcome).
inboxdetailspage.php --> View which displays email contents
mailactions.php --> controller which passes $data to inboxdetailspage.php
This is the function that does it.
function viewInboxDetails(){
$mailId = $this->uri->segment('4');
$data['emailInfo'] = $this->fetchParticularEmailInfo($mailId);
$data['titleText'] = 'Email Information';
$this->load->view('admin/inboxdetailspage',$data);
}
I am absolutely blank on how to achieve this feature
Passing data to the IFRAME from the same controller is not possible.
IFRAMEs' are just basically another URL display on a particular page. Hence all you can do is can pass the data via URL and thats it!
How this can be achieved this is create another (say) link for displaying the mail content by taking the ID from the URL and display that URL in iFrame. For example,
Controller:
public function all_mails()
{
$data['mails'] = $this->xyz_model->get_mails();
$this->load->view('all_mails.php', $data);
}
public function mail_content($mail_id)
{
$data['mail'] = $this->xyz_model->get_mail_content($mail_id);
$this->load->view('mail_content.php', $data);
}
View:
all_mails.php
<?php foreach($mails as $mail) { ?>
<table>
<tr>
<td><?php echo $mail->from; ?></td>
<td><?php echo $mail->subject; ?></td>
<!-- Your email content -->
<td>
<iframe src="/xyz/mail_content/<?php echo $mail->id; ?>"></iframe>
</td>
</tr>
</table>
<?php } ?>
mail_content.php
<!-- Your CSS here -->
<link href="/static/home/css/bootstrap.min.css" rel="stylesheet">
<div>
<?php echo $mail->content; ?>
</div>
First pass $data to your view and from there call another controller which can render your whole iframe from it with its own view.
Create an iframe in the view linking to another function in controller(a new page). In this page display only email contents according to the email.

Creating a link to an id that refreshes the page

I am working on a project that uses javascript to make tabs. It has 3 tabs.
Tab three has an id of tab3, what I need is a refresh button that will be on tab3 that will refresh the page. Problem I'm having is if you click on tab3 it will display tab3 data, but it does not change the url. So the refresh button isn't working.
I tried an onclick javascript that reloads the page using location.reload() which reloads the page but not to the tab3. So I put that on a link,
<a href="<?php echo $_SERVER['REQUEST_URI']; ?>#tab3" onclick="reloadPage();" >Refresh</a>
This will link to the correct location, the URL then has #tab3 at the end, then the Javascript runs and it reloads back to the url without the #tab3.
So I then tried this that I saw somewhere.
Go
Which links, but doesn't reload.
What is the best way to do this?
Try this-
<a href="#tab3" onclick="location.reload();" >Refresh</a>
Using window.location is the solution, however if the current location is already the same as the new url that is assigned, then browser will not re-load the page.
The only trick would be to make the new url look "new". This can be done by adding a random identifier as querystring parameter.
In the form:
http://hostname?<dynamic/random>#tab3
Example:
Go
In head put,
<script type='text/javascript'>
function goto(link) {
window.location = link
}
</script>
and do this to your button
<a onclick=goto("<?php echo $_SERVER['REQUEST_URI'] . '#tab3'; ?>"); >GO </a>
if you want to refresh the page and aslo goto same place this code will work
<form method=post action="">
<input type=hidden name=value value="#tab3" />
<input type=submit value=GO />
</form>
<?php
if (isset($_POST['value']))
{
header('Location: http://'. $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI] . $_POST["value"]);
}
?>

dynamically generating a redirect to an mp3 file with php and javascript

I'm trying to generate the link to the mp3's in my site dynamically using the following code:
<a href="<?php echo "<script language=javascript>location.href='$thisTitle.mp3'</script>";?>" target="_blank" onClick="javascript:PlayerOpen('LFO&#8217;s Revenge',this.href);
return false">Click Me to Hear a Sample</a>
This results in the following url:
http://www.example.com/site/_main_nav/<script language=javascript>location.href='Title 1.mp3'</script>
$thisTitle gets Title 1 from the mysql database.
Do you know how I could fix this? I can't use header('$thisTitle.mp3') because my included header file has already sent the header info which can't be modified. I can't call the included header after this line of code either.
I use the same javascript redirect code in my index file to link to the welcome page:
echo "<script language=javascript>location.href='_main_nav/welcome.php'</script>";
It redirects properly without the javascript code being spat out in the resulting url.
I have the Title 1.mp3 in the _main_nav folder.
change it to
Click Me to Hear a Sample

Categories

Resources