Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts

    :: window.open with the url as a variable - how? ::

    ok im slowly learning this jscript business but this is puzzling me:

    Code:
    function printbutton() {
    	var thispage = window.location.href;
    	var starturl = thispage.split('content')[0];
    	var endurl = thispage.split('content')[1];
    	var printableurl = (starturl + ('printable') + endurl);
    		if (thispage.indexOf("content")!=-1) {
    		document.write('<a href="java\script:;" onClick="openprintable();"><img src="http://www.simonsgroup.com/webimg/navimg/printicon.gif" width="71" height="35" alt="Click for printable page" border="0"></a>');
    		}
    }
    
    
    function openprintable() {
    	  window.open(" printableurl ");
    }
    now, the top bit works and gets the url - now, how the hell can i add the variable printableurl into the window.opener bit? ive tried alsorts and it keeps thinking its a string not a variable any ideas?

    thanks!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You have to pass the printableurl as a string variable to the openprintable function; thus you have to write it's value enclosed in quotes:

    Code:
    function printbutton() {
        var thispage = window.location.href;
        var starturl = thispage.split('content')[0];
        var endurl = thispage.split('content')[1];
        var printableurl = (starturl + ('printable') + endurl);
        if (thispage.indexOf("content")!=-1) {
            document.write("<a href=\"javascript:;\" onClick=\"openprintable('" + printableurl + "');\"><img src=\"http://www.simonsgroup.com/webimg/navimg/printicon.gif\" width=\"71\" height=\"35\" alt=\"Click for printable page\" border=\"0\"><\/a>");
        }
    }
    
    
    function openprintable(url) {
          window.open(url);
    }

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    thanks m8 - would have taken me ages to realise that!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson


  •  

    Posting Permissions

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