Run a Javascript function from the site link?

Asked

Viewed 2,187 times

5

Example have the link:

www.meusite.com.br/index.php?subject=conteudo do assunto;message=teste de mensagem

I want to call the function onclick of that button automatically:

<input value="Enviar" tabindex="3" onclick="return submitThisOnce(this);" accesskey="s" class="button_submit" type="submit">

What I change in the link to call this click function?

Follows the function:

function submitThisOnce(oControl)
{
    // Hateful, hateful fix for Safari 1.3 beta.
    if (is_safari)
        return !smf_formSubmitted;

    // oControl might also be a form.
    var oForm = 'form' in oControl ? oControl.form : oControl;

    var aTextareas = oForm.getElementsByTagName('textarea');
    for (var i = 0, n = aTextareas.length; i < n; i++)
        aTextareas[i].readOnly = true;

    return !smf_formSubmitted;
}
  • there is the function submitThisOnce? if yes then I think to withdraw the Return should already resolve

2 answers

3


If I understand your question, it is possible to do this via Javascript as follows:

function suaFuncao() {
    alert('sua função');
}

/*Pega o evento de Load da pagina*/
(function() {

    /*Pega a url atual*/
    var urlAtual = window.location.href;

    /*Seta a url para chamar a função*/
    var urlParaRedirecionar = 'www.seusite.com.br';

    /*verifica se é para execultar a função, se sim, ele a execulta*/
    if(urlAtual == urlParaRedirecionar) {
        suaFuncao();
    }

})();

To not need to compare the entire url, you can pass a parameter via url saying it is to redirect, as in this reply :)

  • The problem is I can’t change the page

  • 1

    My friend without page access, only via URL you won’t get a way to do :, ( because the URL is just your navigation tool :( what you can do is create an extension in Chrome to do it for you :)

  • Fine, I’ll be if the developer changes there

  • All right, if you need anything, you can call me here =D

0

Let’s put the full example right, lacked its function script ai, but let’s assume it here in the answer.

<input value="Enviar" tabindex="3" onclick="submitThisOnce(this);" accesskey="s" class="button_submit" type="submit">
<script>
function submitThisOnce( $input ){
// faz alguma coisa antes do submit
}
</script>

Some say the right thing to do onclick="javascript:submitThisOnce(this);" how it works of the two ways I write of laziness without the javascript:

  • 1

    I’ve completed the function. I didn’t understand much, I can’t make any changes in the code of the page, I just want to manipulate it through the link the site.. As in the example I put in the post, I wanted to call/execute the function by the link

Browser other questions tagged

You are not signed in. Login or sign up in order to post.