change div content when parent page is different? - php

i want to change a div content when my page embed into another page
for exemple:
if the visitor access directly to the page:
<div id="msg"> this is my page </div>
if my page embed into a frame
<div id="msg"> my page into anthor page :)</div>
thanks for advance.

You can easily check if page is in iframe using this trick:
var isInIFrame = (self != top);
So, you check it on page-loading and get something like this:
$(document).ready(function() {
var isInIFrame = (self != top);
if (isInIFrame)
$("#msg").text("my page into anthor page :)");
});
And default value "this is my page" should be in markup file.

You could do it with javascript (client side only). From this link;
http://billhiggins.us/blog/2009/04/09/detecting-that-youre-in-an-iframe/
You could do the following with javascript;
<script type = "text/javascript">
if(window !== top) {
document.getElementById("msg").innerHtml("My page into another page")
}
</script>
Not tested, and from reading that article, issues to consider, but hopefully this gets you in the right direction.

You can try:
if (window != top) {
document.write('<div id="msg"> my page into anthor page :)</div>');
} else {
document.write('<div id="msg"> this is my page </div>');
}

You might be able to accomplish this with JavaScript. You can detect whether your window object is the top-level browser window:
if (window === top){
alert("I'm the top.");
} else {
alert("I'm embedded.");
}

Related

Fancybox 3 on page load with delay and set cookie not working

I can not get this jQuery to work on page load? I use fancybox 3.
<script>
function openFancybox() {
setTimeout( function() {
$('[data-fancybox data-src="#newsletterFancy"]').trigger('click');
}, 20000);
}
$(document).ready(function() {
var visited = $.cookie('visited');
if (visited == 'yes') {
return false;
} else {
openFancybox();
}
$.cookie('visited', 'yes', { expires: 7 });
$('[data-fancybox data-src="#newsletterFancy"]').fancybox();
});
</script>
I have also added this to my body tag: <body OnLoad="openFancybox()" class="body">
I basically have my pop up in a included file called newsletter.php. The link in my sidebar works fine when i click that. But i want to make it pop up and open on page load with a delay and also for it to set a cookie.
I have also included the cookie js as well:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
This is the line I use in my sidebar link for it to open when you click it:
<a class="buttons" data-fancybox data-src="#newsletterFancy" href="javascript:;">Newsletter Subscribe</a>
Thanks
You are simply not using valid selector. Replace
$('[data-fancybox data-src="#newsletterFancy"]')
with, for example:
$('[data-src="#newsletterFancy"]')

redirect using jquery in zend framework 2

I am trying to open a link "homepage/about" in a div in zend framewrok 2. The link opens successfully using the jquery script but the logic is to when the session has ended and the same link is used again it should redirect to a login page. But for me the redirect opens in the same div that is suppose to have the page "homepage/about". Below is my code for the html page:
<div>
<a id="Load" href="homepage/about">Home</a>
About
</div>
<div class= "mainContainer" id="LoadMe">Target div</div>
and the jquery script is as follows:
<script>
$('#Load').click(function() {
$('#LoadMe').load($(this).attr('href'));
return false;
});
</script>
I want the redirect to take me to the login login page rather than it opening in the target div.
You can for example set the href via zend and do in Jquery like this:
$('#Load').click(function() {
if( $(this).attr('href') == "" )
{
window.location = "login.html";
}
else
{
$('#LoadMe').load($(this).attr('href'));
}
return false;
}

redirect to a specific page from php

Hello I am using following code to open a page in PHP
header('Location :login.php');
but the problem is that this is doing inside the div of page, when I clicking on that the page is being loaded inside the DIV not on the fill screen, what should I write here to solve the problem?
edit
I am loading the page like this
javascript, in main.php
var div = document.getElementById('content');
var url = 'my.php';
div.innerHTML = '<iframe style="width:100%;height:100%;" frameborder="0" src="' + url + '" />';
and I give a link to logout in my.php, here I need to open a login page and destroy the main.php page
Instead of returning a redirect (which redirects only your frame) like you do now, you'll have to have the top frame redirected.
Since your code gets loaded in an IFRAME, you'll need to change the TOP frame position, instead or returning a header, return the following javascript:
<script type="text/javascript">
window.top.location = "http://www.example.com/path/login.php";
</script>
The trick is to use window.top instead of window.
You are displaying stuff before header is sent.
if ( !headers_sent() ) {
header("Location: login.php");
} else {
echo '<meta http-equiv="refresh" content="0;url=login.php">';
}
Javascript redirect.
<script type="text/javascript">
window.location = "http://www.domain.com/login.php";
</script>

Symfony link_to popup on the layout doesnt work

I have a layout base page. On this page I have a link_to to open up a popup:
<?php $options = 'left=100,top=10,width=650,height=375,location=no,scrollbars =yes,resizable=yes,directories=no,status=no,toolbar=no,menub ar=no' ?>
<?php echo link_to(image_tag($profile_picture, 'size=25x25') .' ' .$sf_user->getAttribute('user')->getUsername(), '/frontend_dev.php/user/' .$sf_user->getAttribute('user')->getId(),
array(
'popup' => array('popupWindow', $options)
)
); ?>
When I click the link the user page opens but not in a popup window. But when I click the same link in the user page, it opens the user page in a popup window. I even tried a plain HTML a link with an onclick:
Google
And it still didn't open a popup window from the layout, but from the user page it does!
Can someone please explain to me what I'm doing wrong?
Maybe you're asking how I'm loading the userpage, well like this:
<?php echo $sf_content ?>
And user page does simple HTML with PHP, so nothing special about that.
EDIT:
Well it had something to do with the index page of the sfGuestBookPlugin, it has a
<script type="text/javascript">
$(document).ready(function() {
});
</script>
part, and I had my own part of JS in another script tag at the bottom of the file:
<script type="text/javascript">
var open = true;
$(".form-title").click(function() {
if(open) {
$(".openClose").text("▼");
open = false;
} else {
$(".openClose").text("▲");
open = true;
}
});
</script>
What helped is move this part within the $(document).ready() part. But I'm still curious about why this is helping. If you could please explain?

Pop up is not working correct, does not refresh the page

I try to open pop up in the same window, but it forwards me to another. Also, I try to refresh window after pop up closes, but I don't find easy solution. I think the best is not to put # to the URL. That is my function:
<li value="Open window" >
<a href="javascript: window.open('upd.php?m=<?php echo $oldpar?>','','width=520,height=400')">
<u>EDIT</u>
</a>
</li>
I manage open the window, however main page also goes to javascript: window.open('upd.php?m=2','','width=520,height=400'). I tried to put:
<script type="text/javascript">
<!--
function refreshParent()
{
window.opener.location.href = window.opener.location.href;
if (window.opener.progressWindow)
{
window.opener.progressWindow.close()
}
window.close();
}
//-->
</script>
It would be great to close pop up automatically after user select variables and press button. Immediately after the parent(main) URL would refresh.. Any help? :)
P.s. any ideas how to auto refresh pop up? I saw all browsers have different way of doing that.. Common one?
Use "_self" as the window title (second parameter to window.open()) to open the pop up in the same window.
Use window.location.reload(); to reload the current window.
Use opener.location.reload(); to reload the window that opened the popup before calling window.close();
To open the windows via link:
Open
The js function to open a link:
<script language="JavaScript">
function open(w,h,URL)
{
var width = w;
var height = h;
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
window.open(URL,'janela', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
}
</script>
And Finally in the end of your "popup" you should close the windows after all task get done, just telling the script to close the popup and reload the opener page.
<script language="JavaScript" type="text/javascript">
function close()
{
opener.location.reload();
window.close();
}
</script>
I'm not sure, but I guess you've been looking for that.
​<ul>
<li value="Open window" ><u>EDIT</u></li>
</ul>
return false; at the end of the call should solve your problem.
UPD:
http://jsfiddle.net/Mt8Vd/

Categories