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

3
  • Where you are using document.location? Commented Dec 31, 2013 at 13:08
  • 1
    Am not sure, I did understand your querstion. Commented Dec 31, 2013 at 13:10
  • i have used instead of document.write,but it didnt work Commented Dec 31, 2013 at 14:46

5 Answers 5

3

you can use

 window.location.href
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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

5 Comments

it is not working ..window.location.href and location.href,both are not working..and if i m doing like document.write('<a href="yoursite.com';">link</a>'); if i do like that it goes to the next page and shows the link and then have to click on that
what is it that you want to do?
means..i just wanted to switch directly to another page,
but your window.location.href and location.href is not working,
you may want to use firebug to debug your javaScript because it should work the only issue i can think of is that you have a function with an error
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.

4 Comments

yeah that's true that environment is in Google Apps Script,thanks alot for that
but i got how do we use :<?var url=getScriptUrl();?> <a href='<?=url?>?page=form'> in any conditional operator...
ok..as you mention that in your link <?var url=getScriptUrl();?> <a href='<?=url?>?page=form'> <label><input type="button" onclick="abc()" id="log" value='SUBMIT' class= "btn btn-danger"></label> </a> 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!!"); }
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..
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!!");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.