2
<label>
    <input type="button" onclick="abc()" id="log" value='SUBMIT'>
</label>
<script>
    function abc() {
        google.script.run.withSuccessHandler(callback).processForm(document.forms[0]);
    }

    function callback(ste) {
        if (ste == "true") {
            var a = document.getElementById('log');
            document.write(a.value);
            document.write('<a href="http://www.w3schools.com/js/js_htmldom_html.asp">do stuff</a>');
        } else document.write("false");
    }
</script>

as i m using document.location && window.location both are not working to switch page,is there any other method which can help me out to

Sergio
  • 28,539
  • 11
  • 85
  • 132
ashishSober
  • 1,181
  • 1
  • 13
  • 23

5 Answers5

3

you can use

 window.location.href
Manish Jangir
  • 5,329
  • 4
  • 42
  • 75
1
 function callback(ste) {
        if (ste == "true") {
            var a = document.getElementById('log');
            location.href='http://yoursite.com';
//or put your url into var and put it there
        } else document.write("false");
    }
Farhad
  • 1,873
  • 17
  • 28
1

This is a simple thing. Before askin you should do research.

You can use:

function callback(ste) {
        if (ste == "true") {
            var a = document.getElementById('log');
            window.location.href='http://yoursite.com';
//or put your url into var and put it there
        } else document.write("false");
    }

if you are not sure about anything please comment.

http://www.sivamdesign.com/scripts/navigate.html there are a few examples which shows the scripts on how it works

0

You've left clues, including the tag and the call to google.script.run, but your question should make it clearer that this code is being hosted from the Google Apps Script environment. That limits the solution, as described in the documentation for Class HtmlOutput.

You are trying to redirect the browser to a new URL, which is not allowed in Apps Script web apps.ref

That means that none of the other provided javascript solutions will work. Your work-around of presenting the user with a clickable link is your only option for redirecting to an "external" URL. (external == not your web app)

You can provide the illusion of a redirect to another html page within your Apps Script WebApp, though. See this answer for an example of serving multiple html pages using HtmlService. The basic idea is to write doGet() to accept a query parameter that it will use to select which html page to serve.

Community
  • 1
  • 1
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
  • yeah that's true that environment is in Google Apps Script,thanks alot for that – ashishSober Dec 31 '13 at 18:12
  • ok..as you mention that in your link that's true that is directly working for the button... but i need that in "if" statement like... function abc(){ google.script.run.withSuccessHandler(callback).processForm(document.forms[0]); } function callback(ste){ if(ste=="true"){ alert("i LOGIN"); //wanted switch my page here } else alert("Login Failed!!"); } – ashishSober Jan 02 '14 at 14:38
  • yeah i also done this...u r right that's not possible...actually i was trying to make a login page...without using session...so little things gone nasty..thank you so much by the way.. – ashishSober Jan 02 '14 at 18:26
0
    <?var url=getScriptUrl();?>
    <a href='<?=url?>?page=form'>
           <label><input type="button" onclick="abc()" id="log" value='SUBMIT' class= "btn btn-danger"></label>
    </a>
    </form>

<script>
function abc(){
google.script.run.withSuccessHandler(callback).processForm(document.forms[0]);
}

function callback(ste){
if(ste=="true"){
alert("i LOGIN");
// want to switch it here
}
else
alert("Login Failed!!");
}
IroMp
  • 31
  • 1
  • 9
ashishSober
  • 1,181
  • 1
  • 13
  • 23