Reload page and take the user where the cursor is - php

Is it possible to take the user where the cursor is after reloading the page? I'm enabling a <textarea> on the basis of some URL parameters on page reload using PHP. But in the new window the textarea will open on the bottom of the page. If the page is already lengthy the textarea will be hidden beneath.
Is there any way so that after reloading the page the textarea appears on the viewport so that it can be filled?
I tried:
Write
...
<a href="#ok">#<a> <!-- setting a bookmark to get the viewport here -->
<textarea><textarea>
I know there are plenty of solutions using AJAX, using lightbox etc. But I need a generic way, may be HTML or a server-side solution. Or, in a nay-say it can be jQuery.

It doesn't appear that you are using the anchor (or bookmark, as you called it) correctly. If you give the <textarea> tag an id of "ok" you should be able to link directly to that area of the page by using the # in your link to the page. Example: somepage.html#ok
There is no need to use the <a> tag to create an anchor. That is outdated.

Related

How to Make Auto Clicking For A Specified Link

i want a php code for automatically clicking on a Specified text or link on a page.
thanks
You want to use JavaScript code.
Just insert a script tag just before the closing body tag on the web page. It should look something like this:
<script>
document.getElementById("#my-link").click();
</script>
That will click the link with the HTML ID "my-link".
Note that generally this is not a good idea to implement. If you need to forward the user to another page, you can do that without simulating a mouse click - in PHP you can use the code
header("Location: redirectToHere.php");
and that will redirect the user automatically. If you need to change things on the page, you can do that by directly setting their properties with JavaScript.

How do you extract a HTML link text node in PHP once link is clicked?

I am using a PHP foreach loop to list a series of links on a HTML page, which are rendered using jquery mobile. When one of the links is chosen, I want to be able to use the link label in PHP code to query a database and generate the header and other data for the destination page.
The problem is detecting which link was chosen. It seems that an "onclick" event would be involved, but that might mean using Javascript. I've seen an example of placing PHP inside a HTML form, but that relies on using a submit button to create a $_POST input. In my case, the link would be the only button involved in the event,so creating a separate Submit button would not make sense.
You can add query parameters to the links. (e.g. ?id=foo) and then pick them up in PHP via $_GET['id'].

Iframe navigation breaks Firefox back button - workaround?

There is an annoying bug in Firefox where navigation in a dynamically created iframe, which is then removed via Javascript, results in the inability to go back using the Firefox back button (you have to use the drop down and navigate back a further couple of pages).
I am using a form in an iframe which validates and submits data. On form submit/data validation the page in the iframe gets refreshed. This breaks the Firefox back button as above.
I need a solution to try and solve this issue and I've currently tried a few different things without much success:
Storing each iframe page refresh in a session variable (PHP) and then using history.go(-{session var}) in my jQuery code to navigate back. However this only seems to work when navigating back to the page BEFORE the iframe loaded, not the page where the iframe is loaded (in the later, it still breaks the back button)
Hiding the iframe rather than removing it - semi-works but requires multiple back button clicks and brings up the 'do you want to resubmit this data?' message
Reloading the iframe when the user has closed it. No advantage doing this as if you go back you have to still go through all the previous iframe gubbins.
Any suggestions appreciated - but please note: I want to use an iframe, do not really want to use ajax and would love a solution that is cross-browser compatible (ha!).
If you're interested, steps to reproduce this problem:
In Firefox try the iframe example which loads Google on the fancybox
homepage: http://fancybox.net/home
Search for something, i.e. load a new page in the iframe
Close fancybox frame
Try and go back without resorting to the back dropdown list
Incidentally, IE handles this scenario more gracefully than either Chrome or Firefox!
I've given up on this as have tried everything under the sun. Resorting to posting data via jQuery's AJAX methods which won't add a history item.

Facebook style comment box using jQuery

i was working on a facebook like website.and im really impressed with the facebook's commentbox.the toggle stuff are really awesome.can someone help me get something like that.
please dont send me this link http://demos.9lessons.info/multislide.php this is the most famous link on internet but i dont think it is like facebook from any point of view.please i need some serious help !!!!!!!
Well you already know the answer, no not the link you pasted, what you tagged your question with:
jQuery
You need to use AJAX via jQuery and modify a with CSS to get exactly what you want. You're coding in PHP so get use to the idea of making your own web controls by hand, it's very easy.
I doubt you're going to find anybody that'll write the code for you, and from the sound of it, you have done your homework and shopped around at the various script sites. What I would suggest is to break down the behavior of what you're looking for and what you have:
Facebook:
Simple link: "Comment"
Thin text box: "Write a comment"
Clicking link creates div under link or setting focus to text box transforms text box into textarea and button.
Clicking outside of div removes div from page.
When button is pushed and comment is made, a div is added between the original div and the link containing the text of the comment.
When textarea does not have focus, it returns the textarea back to its original state as a text box.
Perhaps it would be best to take the code already written for the link you posted and do these things to it:
Remove transitions
Change button elements into <a> tags
Make the "slider" box visible all the time, but have the contents shift
The box should have an <input type="text"> in it with an onfocus="" attribute set so that we can hide it and show the textarea when it's been clicked in
The textarea and button should be hidden until instructed to become visible (display:none)
Use a jQuery plugin to hide the textarea and button and revert to the text box when the comment div has lost its focus(es).
Hope this helps to some degree.

Scrolling to an anchor in a programatically loaded DIV (from an iframe)

I have a page called results.php that has a hidden iframe and a DIV container. When the page is loaded, some code is run in the hidden iframe which, when complete, loads the results into the CONTENT DIV in the results page, generating a scrollbar to results.php
All this works fine, but when I have anchors in the code generated within the DIV (and finally displayed by results.php) they do not work. I have tried location.hash, scrollto and others, and none work. If I display page source code, I do not see any of the contents (as they were created in the iframe and then loaded into the RESULTS DIV), which is probably why location.hash and such don't work. Also, getElementById does not see any of the anchors, I guess because of the same reason.
Any ideas how to get this to work?
Thanks!
The page loaded into the IFRAME has a different context than the page containing the DIV. If you are trying to access the outer contents from the inner IFRAME, you have to go through contortions to get the parent document from the nested document. That may vary depending upon browser.
Assuming your iframe has id 'results', and your anchor has id (not name) 'my_anchor', this should work:
var iframe_doc = document.getElementById('results').contentWindow.document;
var anchor = iframe_doc.getElementById('my_anchor');
anchor.scrollIntoView();

Categories