Open link in iframe and then open another link in same window - php

I have this code:
echo 'Send map to 2nd screen';
Id like to be able to press this link, which opens the case_util.php in another iframe and then goes to another link in its own iframe.
Sort of like a refresh/going back. However, it is a form, and pressing back retains the data in the form. I dont want this data in the form, hence I'd like it to navigate to the page.
Thanks :)

Syntax issues. document.location is not a function and is deprecated anyway.
Here is a better version
echo 'Send map to 2nd screen';
or easier to read since you want the href in the iframe named second .
...?> <a href="case_util.php?status=green&adr=<?php echo $adr; ?>" rel="nofollow" target="second"
onClick="window.location='create.php'" >Send map to 2nd screen</a>

Best answer:
Don't use iframes.
However if you are determined to use something as silly as an iframe, use something as silly as a meta redirect.
<meta http-equiv="refresh" content="0;url=http://example.com/"/>
;) seriously, just read about AJAX+jQuery instead:
http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/

Related

PHP Referrer of Referrer (Recursively)

I am looking into sending the user back two (or maybe more) pages from where they came. What works so far is
<strong>
<a href="javascript:history.go(-3)">
Click here to go back to the view
</a>
</strong>
However, the [history] page being called does not refresh to show the changes.
So I have the idea of referring the referrer. PHP gives me $_SERVER['REFERER'] to use, which is OK but only up to one level. How do I get the referrer (of referrer...) of $_SERVER['REFERER'] ?
As far as I know, you cannot do that in PHP. The simple answer is no, because PHP is server-side, and gets just the current referrer, while Javascript is client-size, running on the browser, which actually does have 2 or more history steps.
Consider re-thinking why you want this to happen. You can never guarantee that the 2-step back referrer (even the last one) is still in your site.
Pure JS. No PHP.
Modify your existing code like this.
<strong>
<a href="javascript:window.name='autoLoad';history.go(-3)">
Click here to go back to the view
</a>
</code>
Now add this JS to the page, where you are being redirected. say test.html when you click history.go(-3)
function autoLoad(){
if (window.name=='autoLoad') {
location.reload();
window.name='';
}
}
and in the body tag add this
<body onload="autoLoad()">
In server variable $_SERVER['REFERER'] is only the last referrer. If you want to use previous you have to save them to session. The problem is that you can't find out which browser tab initialized the request - so your history would be mixed for all tabs.
Solution would be using JS to force the browser to reload page.
You could do something like this, or use cookies if you like them more, but you don`t need PHP for this.
<input type="hidden" id="reload" value="0">
<script type="text/javascript">
window.onload = function(){
var el = document.getElementById("reload");
if(el.value != "0")
{
window.location.reload();
}
el.value="1";
}
</script>

Making (or passing) an <a href> php variable invisibly on a link

Is there a way to put a php variable in an without it automatically being visible, like a GET variable?
Some click
I want the subsequent browser URL to be www.myphpfile.php (no variable visible).
Thanks for any help.
If I understood you right you want to have something like this:
Start a session and write the contents of $_GET['location'] into, e.g., $_SESSION['location'].
Redirect the user, e.g. header('Location: myfile.php');
If the user changes his location, start at 1
You could create a form for it with method="post" and style the submit button as a normal link using CSS.
That is if I understood you question correctly.
You should use <a href="fake" onclick="window.location=real">, but I prefer use links as The Lord W3C has declared originally.
Edit:
<a href="javascript:goto(nice_url_like_thing)">;

Trying to load a different iframe within a div popup box depending on which of several links is clicked to open the box

I have an overlay popup box (DIV + JavaScript + some CSS) which is toggled by a link, like this:
<a href="#" onclick="popup('popUpDiv')">
The box that pops up contains an iframe. Now I want different links on my page to load different iframes when the box opens; so that link A would toggle the box to appear, and load iframe1.html inside the box, while link B would toggle the same box to appear, but load iframe2.html inside the box, and so forth.
I'm a beginning programmer, and I first figured maybe this could be done with PHP, by putting something like this inside the popUpDiv:
<iframe src="http://mysite.com/iframe<?php echo $_GET ["iframeid"] ?>.html">
... and then simply adding ?iframeid=x to each link's href, where x is the id of the iframe to be loaded.
This obviously won't work in practice though, because it requires a page reload, and when the link is clicked, the popUpDiv is toggled to open, but at the same instant, the page reloads, now with the ?iframeid=x query string in place, but too late, since the popUpDiv disappeared on reload.
Is there perhaps a JavaScript equivalent that could be used, or can anybody suggest another way to make this work?
FYI, this is the kind of popup box I'm working with:
http://www.pat-burt.com/csspopup.html
I finally found a really simple way of accomplishing this without additional JavaScripting, by simply using the target attribute:
<iframe name="myfavoriteiframe">
Then:
This is a link.
P.S. Just FYI for any of those out there who might want to use this feature with Vimeo's JavaScript API, as I'm doing: In order to make API buttons work with this target method, it seems like the iframe src-attribute cannot be left blank. You need to specify a link to any of your videos in the src, so that a video loads into the iframe on page load, like this:
<iframe name="myfavoriteiframe" id="player_1" src="http://player.vimeo.com/video/[the_number_of_your_video]?api=1&player_id=player_1">
I simply inserted the URL to the first video on my page, but you can use any of them, since they're hidden anyway.
Then link to any of your videos using the target method described above, and the pre-set iframe video will be replaced by a video of your choice.
Create two divs with the two variations of content (the two iframes with each specific URL). Then toggle by the name of the div.
<a href="#" onclick="popup('popUpDiv1')">
<a href="#" onclick="popup('popUpDiv2')">
Set the id attributes of the div elements appropriately.
Rather than adding something to the popup DIV element, I would add a required link to the href property of the link that you use to open the popup:
<a href="http://example.com/first/uri" onclick="pre_popup('popUpDiv')">
<a href="http://example.com/first/uri" onclick="pre_popup('popUpDiv')">
<a href="http://example.com/first/uri" onclick="pre_popup('popUpDiv')">
And then inside the popup function I would take the href parameter of the link that has triggered the event and use it in a popup:
function pre_popup(id) {
// Take the href parameter of the link
var href = this.href;
// And then use it in the iframe
window.frames["your_iframe"].src = href;
// And then pop it
popup(id);
}

PHP anchor question

Is there a way to reload a PHP page when a users clicks a PHP link and then have the page jump to a certain spot on the same page using PHP or JQuery like an HTML anchor?
Here is the PHP link below.
' . $user_name . '
You can just use a hash link, for example:
'.$user_name.'
If in that page you have anything with that ID, say:
<div id="section">
Then it'd scroll down to there, no jQuery or JavaScript needed...this is normal browser behavior. You can read more about it in the HTML4 spec here.
As an example, here's a link to the answer you're reading, see the auto-scroll when you visit it? :)
https://stackoverflow.com/questions/3163053#3163061

open window with dynamic content

Is it possible to open a window from PHP that has predefined content? It's obvious how you can open a window from a javascript link that frames an existing page, or just do a target=_blank from a regular a tag that references an existing page. But I am generating a bit of content, and want that content to be opened in a new link (or streamed to the viewer)--
something like (clearly psuedo code!):
$content = "Hello World. <br />Nice to meet you!";
<a href="#" target="_blank" content=$content>Open up!</a>
Is this possible?
Thanks!
Well, the direct answer to your question is that you can't really do it from PHP directly, because it's the browser that's going to open the window. You can, however, have your page open a window, get the document object, and write to it:
var w = window.open("Surprise", "#");
var d = w.document.open();
d.write("<!DOCTYPE html><html><body>Hello World</body></html>");
d.close();
Instead of the simple string "Hello World" of course your PHP script can put together whatever it wants. Additionally, if desired, the Javascript code itself can dynamically generate the content based on page status, form fields, etc.
Note that you can't guarantee that the new window won't be a new tab, which is no different than what happens with "target" in <a> or <form> tags.
edit — oh also: if you try to use window.open outside of code that's running in response to a "click", browsers will probably think you're trying to show a pop-up ad and will block it.

Categories