Welcome to WebmasterWorld Guest from 54.205.17.36

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Position browser in page

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

Junior Member

5+ Year Member

joined:Dec 23, 2008
posts:147
votes: 0


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 Sept 24, 2011 (gmt 0)

Senior Member

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

joined:July 3, 2006
posts: 3123
votes: 0


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 Sept 24, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 23, 2008
posts:147
votes: 0


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 Sept 26, 2011 (gmt 0)

Senior Member

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

joined:Nov 28, 2004
posts:7999
votes: 0


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 Sept 28, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Dec 13, 2009
posts:945
votes: 0


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 Sept 28, 2011 (gmt 0)

Senior Member

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

joined:July 3, 2006
posts: 3123
votes: 0


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 Sept 28, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 15, 2004
posts:941
votes: 0


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 Sept 28, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Dec 13, 2009
posts:945
votes: 0


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)

Junior Member

5+ Year Member

joined:Dec 23, 2008
posts:147
votes: 0


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.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members