...

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



babelfish
07-30-2002, 10:57 AM
ok im slowly learning this jscript business but this is puzzling me:




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!

mordred
07-30-2002, 11:10 AM
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:



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);
}

babelfish
07-30-2002, 11:28 AM
thanks m8 - would have taken me ages to realise that! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum