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?
Related
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"]')
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;
}
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>
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.");
}
I have a simple form which is inside IFRAME. When user click on SUBMIT, it redirects to a specific page on my server. The function I use for the redirect is
header ('Location: mypage2.html');
exit ();
But I want the new page to open in _top location, not inside the same IFRAME that I use. How can I tell the browser to open the new page in _top not inside the IFRAME?
Thanks in advance.
You are not able to achieve the desired effect in PHP. This is something you'd have to do from JavaScript or add target attribute to <form>:
<form ... target="_top">
You can use javascript to access the parent. You could echo out javascript in your PHP.. so your parent page has this:
function changeURL( url ) {
document.location = url;
}
and in your php script, you echo
<script>
parent.changeURL('mypage2.html' );
</script>
The reason you can't call parent.document.location is because it's read only - you have to have a function available on the parent to do it.
A simple way directly in PHP to redirect the parent page rather than the iframe:
echo "<script>top.window.location = '/mynewpage.php'</script>";
die;
The die; isn't necessarily necessary, but it is good "just in case" to prevent the script from continuing any further, for example, if javascript is disabled in the user's browser.
we can use javascript like this :
target.window.location='locationpage.html';
top.window.location='mypage2.html';
The best and simplest thing to do is to use the form target element
<form action="..." target="_top">
<form action="..." target="_parent">
either of the target parameters works fine
You can either link to the page using Break Out or use code
<?php header("Location: pagename.php?Break=Y"); ?>
You then use the following code in the header of the page with
if(isset($_GET['Break'])) //
{
$BreakFrame = true;
$BreakToPage = "pagename.php";
}
<script language="JavaScript" type="text/javascript">
function changeURL( url ) {
document.location = url;
}
</script>
<?php if($BreakFrame) { ?>
<script language="JavaScript" type="text/javascript">
parent.changeURL('<?=$BreakToPage?>' );
</script>
<? }?>
In the page that you want to load in _top, add the follow code in the header
<script type="text/javascript">
if (top != self) top.location.href = location.href;
</script>
For CakePHP 4, to redirect your parent page just add option 'target'=>'_top' in your iframe's link:
Example:
<?= $this->Html->link(__('Redirect Parent'), ['controller' => 'Users', 'action' => 'view'], ['target'=>'_top']) ?>
All the best!
You can add multiple headers to your redirect.
I use a little function that I created with this in mind.
public function redirect($url){
header('Window-target: _top');
header('Location:' . $url, true, 303);
exit();
}