Example 14: DOM Manipulation (Part III)
Posted October 9th 2011, 8:00pm
In this example, we will use some document and window-level javascript properties to create something interesting.

Scripts can access the URL of the current page in several ways. The simplest is the document.URL property, which returns the complete URL of the current page. This is useful if you are unsure of the complete URL (such as on pages with user input). You can also access specific portions of the URL with several window.location() properties. In particular, window.location.pathname returns the directory path, which is the portion of the URL starting with the first forward slash and ending with a question mark, and window.location.search returns the query portion of the URL, which (if defined) is the portion of the URL starting with a question mark.

Since forumotion boards use phpBB2 server software, we can use these three properties in an interesting way. If you have set up a login box on every page (either with the login widget or by writing your own), you may have noticed that after login, you are always returned to the homepage. The following script will change that behavior...after login, you will remain on the current page.

First, if you have written your own login HTML, make sure it has followed the forumotion/phpBB2 protocol of having the username and password INPUT tags with IDs of "username" and "password", respectively. We will be using that information. As always, put this script in a javascript file, and set it to be on all pages:

$(function() {
if (document.URL.indexOf('/login')==-1) {
var x=document.getElementById('username');
if (x && document.getElementById('password')) {
$(x).before('<input type="hidden" name="redirect" value="' + window.location.pathname + '" /><input type="hidden" name="query" value="' + window.location.search + '" />');
}
}
});

There are countless other examples of similar types of useful scripts that you could write using global variables. I hope you try a few!
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
Example 14: DOM Manipulation (Part III)
Posted October 23rd 2011, 5:31am
excellent tutorial.
Personally I hate forumotion pages that appear after adding a reply & especially after voting a reply...asking user return to your message & your vote has been cast. Those pages can be skipped...will giv it a try.


But verbally can you explain this part
dion said:
document.URL.indexOf('/login')==-1
φ
Posts:
Avatar
Guest
Example 14: DOM Manipulation (Part III)
Posted October 23rd 2011, 6:12am
The indexOf() method searches for a character or string within a string and returns the index position.
For example:
X="hello"
X.substring('h') is 0
X.substring('hel') is also 0
". ". ". ('o') is 4
" " " ('b') is -1

If the character or string does not appear in the string then -1 is returned.
φ
Posts: 509
Joined: July 9th 2011, 11:00pm
Location: England
Likes Given: 15
Likes Received: 26
Example 14: DOM Manipulation (Part III)
Posted October 25th 2011, 1:39pm
I have successfully tested Dion's tutorial.

@LGForum
Login forum code given at forumotion & by you in that sliding panel thread willnt work with this because you haven't included respective username/password ids.
I used
<form action="http://engineering.forumotion.info/login.forum" method="post"><table cellspacing="1" cellpadding="3" border="0"><tbody><tr><td width="25%" align="right"><br> Username:</td><td><input type="text" name="username" id="username" size="12" maxlength="40" /></td></tr><tr><td align="right"><br>Password:</td><td><input type="password" name="password" id="password" size="12" maxlength="32" /></td></tr><tr align="center"><td colspan="2">Remember me: <input type="checkbox" name="autologin" checked="true" /></td></tr><tr align="center"><td colspan="2"><input type="submit" class="mainoption" name="login" value="Log in" /></td></tr></tbody></table></form>


it neatly fits in my modal popup...thnx for help
φ
Posts:
Avatar
Guest
Question about this topic....
Posted January 20th 2012, 11:30pm
[url=/t8380-example-14-dom-manipulation-part-iii]http://www.diondesigns.org/t8380-example-14-dom-manipulation-part-iii[/url]


Firstly I'm not exactly sure of what it does, but I am interested in the part that says this could possibly remove the pages that appear when you press the post button etc... 'your message was successful' page, can this code be modified to suit that?
φ
Posts:
Avatar
Guest
Example 14: DOM Manipulation (Part III)
Posted January 21st 2012, 3:29am
For a short answer NO. This is something different
φ
Posts: 163
Joined: August 5th 2011, 11:00pm
Location: Pakistan
Likes Given: 34
Likes Received: 3
Example 14: DOM Manipulation (Part III)
Posted January 21st 2012, 4:12pm
:) Thanks for sorting that out for me
φ
Posts:
Avatar
Guest

Who is online

Users browsing this forum: No registered users and 0 guests