Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: open new page plus call function

  1. #1
    Join Date
    Jul 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default open new page plus call function

    Hi
    Just a quick question..hopefully a simple one for you guys.

    I have 6 pages in a site im building, with hidden <div> tags. In each of these pages there are links to change the display property of specific divs.
    This all works fine.

    The issue is, that from the Sitemap in the footer, I want the links to open the new page AND change the display property of a specific div to "block"


    I hope that makes sense. If you need more info just let me know.

    Thanx in advance for any suggestions.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Let's say the page you are opening is info.htm, and the function you want to run is a simple alert. The link to that page could be like:

    HTML Code:
    <a href="info.htm?var1=bob">Whatever</a>
    Then on info.htm you could have:

    Code:
    <script type="text/javascript">
    function getQval(n) {
    	if(typeof n !== 'string'){
    		return null;
    	}
    	var r = new RegExp('[?&;]' + n + '=([^&;#]*)'), m = location.search;
    	return (m = r.exec(m))? unescape(m[1]) : null;
    }
    
    if(getQval('var1')){
    	alert(getQval('var1'));
    }
    </script>
    In this case it would alert 'bob'. I think you can see how this could be used to achieve your objective. If not:

    Please post a link to a page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jul 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Sorry.. im quite competent with javascript, but maybe not THAT competent.

    heres the scenario..

    each page has hidden divs (display:none) with links to call a function that changes that to (display:block)
    these work fine from within the page itself.

    What i need is from the sitemap to open the new page and call the function to change display:block.

    eg.. sitemap
    Networking (main page)
    -network design (link on page)
    -network setup (link on page)
    -network security (link on page)

    when i click on Networking, it will open the page "network.asp"
    ..BUT.. when i click say, "network setup" i want it to open network.asp page, AND set display:block to the "networksetup" div.

    In effect, opening the right page, and showing the right content from each link in the sitemap.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Do you have the script to set the display on the desired division? If not, try:

    http://www.dynamicdrive.com/dynamici...edcollapse.htm

    especially its 6th listed ability under its description heading:

    6. Ability to expand the DIVs via a URL parameter string that overrides any default settings/persistence.
    as explained in detail here:

    http://www.dynamicdrive.com/dynamici...uppliment2.htm
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jul 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    yeah I already have the code for the divs to show and hide. all working.

    I actually did have a look at that link you posted before, but i found that after I had got the functions to work on the divs now. And time is running out so i'd rather not change it.

    Which is why im hoping there is some way to open the new page with the function call to show the specified div.

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, just use my example link and code from my first post in this thread. Only instead of doing:

    Code:
    if(getQval('var1')){
    	alert(getQval('var1'));
    }
    do whatever it takes to expand that div. I don't know because I don't have your code. Lets say your expand function is called expandit.

    You would want something like so:

    Code:
    onload = function(){
    	if(getQval('var1')){
    		expandit(getQval('var1'));
    	}
    }
    Or, if you want to be sure it doesn't conflict with other onload events:

    Code:
    if(getQval('var1')){
    	(function(){
    		function init(){
    			expandit(getQval('var1'));
    		}
    		if (window.addEventListener){
    			window.addEventListener('load', init, false);
    		}
    		else if (window.attachEvent){
    			window.attachEvent('onload', init);
    		}
    	})();
    }
    If you want more help:

    Please post a link to a page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Jul 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    the function just hides all divs with specific "name" and shows the one with the specified "id".

    Code:
    function showmain(pass) {
    var divs = document.getElementsByAttribute('name', 'main_content');
    for(i=0;i<divs.length;i++){
    if(divs[i].id.match(pass)){
    if (document.getElementById)
    divs[i].style.display="block";
    else
    if (document.layers)
    document.layers[divs[i]].display = 'block';
    else 
    document.all.divs[i].display = 'block';
    } else {
    if (document.getElementById)
    divs[i].style.display="none";
    else
    if (document.layers)
    document.divs[i].display = 'none';
    else
    document.all.divs[i].display = 'none';
    }
    }
    }
    when i call the function, it works like a charm, from within the page...i need to keep that working, but also to work when opening a new page.
    If you have a look at the site, down the bottom in the Sitemap, thats where i need help with. WEBSITE

    Thanx again for your help, i really appreciate it.

  8. #8
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    So basically you just need two things to happen within one call? And assuming you've already made a function with changes a DIV's style, display property, just add this:

    Code:
    <a href="networkingpage.htm" target="_blank"><span onclick="showdiv('network');">Networking</span></a>
    It may be a little redundant but it should work.
    - Mike

  9. #9
    Join Date
    Jul 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    that looks like it would show the apropriate div, in the current page..changing _target to self, will simply open the page, but the function wont be called.

    what i need is to open "network.html" and within that page to call the function to show the specified div.
    so for eg... say im on home.html, and i want to show "networkdesign" div. which isnt in home.html, its located in network.html.
    When i click on Network Design link in the sitemap, I need two things to happen.
    1 - open "network.html" page.
    2 - call function showmain("networkdesign")

    read my second post, i described it better in there.

  10. #10
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Ah okay, you need to incorporate something in the URL then.

    Like: "newpage.php?div=certain_div"

    Then within newpage.php, call that value.

    Code:
    <script type="text/javascript">
    window.onload = function() {
       showdiv("<?php echo $_GET["div"]; ?>");
    }
    </script>
    - Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •