Welcome to WebmasterWorld Guest from 54.145.173.36

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Position browser in page

   
4:52 pm on Sep 24, 2011 (gmt 0)

5+ Year Member



This may not be a PHP question, per se..
(Probably it's just a boneheaded question... )

My PHP script is reading a stands-on-its-own HTML page to change
certain text strings therein and push it out to the browser.

What I would like to do is position the browser within the page
ala a named anchor.

Is that even do-able?

Thanks, Jonesy.
5:31 pm on Sep 24, 2011 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



What I would like to do is position the browser within the page


? <=> Position the page within the browser?

You are changing the content of the page already, so you could add inline style as well I guess to position a page element? Is it just this one page?
8:08 pm on Sep 24, 2011 (gmt 0)

5+ Year Member



What I want to do is position the browser window to a specific
location in the page as you would with an HTML#named_anchor request.
4:37 pm on Sep 26, 2011 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



So you're opening a new window and want it to position where you click?

If that's the case, the first thing to do is return false on the link,

<a href="my_new_window_function(); return false;">

But that's not really the best way to do it. You might be better served by having a hidden element,

#answer-object { display: none; }

<p><a href="some-link" onclick="return myFunction();">blah</a></p>
<p id="answer-object"></p>

Then on click of the link, write to the page using the <p> as a container, set the object's position and z-index relative to "wherever it is now," and make it visible by setting it's display to block.

This would be Javascript, but not even sure if that's the right answer . . .
12:13 am on Sep 28, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



You can move the window's position through jQuery's scrollTop function [api.jquery.com...]

(function($) {
$(window).ready(function() {
$(window).scrollTop(500); // Set the browser to be 500 pixels down the page
});
})(jQuery);

But I wouldn't be surprised if IE doesn't like that.
9:15 am on Sep 28, 2011 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Or, to position the page at an element with id="MYID" then you could use JavaScript's own, non-standard, but universally accepted
scrollIntoView()
method. Works in IE 6-8 (and above I assume), and all the rest.

document.getElementById('MYID').scrollIntoView();


These are all JavaScript solutions - as they will need to be I guess - nothing to do with PHP (but by the sounds of it you would be writing out the JavaScript with PHP I guess?)
10:14 am on Sep 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



perhaps instead of moving the window into certain position (example <div id="myPos"></div>), you can remove/delete all content except that div, and just show that?

A certain knowledge of regular expressions is needed of course, for that approach.
5:37 pm on Sep 28, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



A certain knowledge of regular expressions is needed of course, for that approach.

I'm a great advocator of jQuery :)

$('body').find('*[id!=IdOfElementToShow]').hide();
4:41 pm on Oct 1, 2011 (gmt 0)

5+ Year Member



I'd just as soon stay away from javascript (and jQuery).
What omoutop said about pruning all content preceding the
point where I want to (re)position is the way I'll go.

What I am trying to do is reposition on a form with one or
more fields in error -- a form that is near the bottom of
a page that is (probably) larger than than some browser windows.