jQuery.stayInWebApp icon indicating copy to clipboard operation
jQuery.stayInWebApp copied to clipboard

What am I doing wrong?

Open SonicRevolutions opened this issue 11 years ago • 10 comments

Hi,

I just can't get it to work... Done all I should've done but it still opens Safari. I changed the if statement to this: if($(this).attr("target") != "_blank") so all links except _blank should stay in the web app...

This is the page I'm working on www.pi-gaomovement.com. Any help would be highly appreciated.

Thanks,

Frank

SonicRevolutions avatar Feb 09 '14 14:02 SonicRevolutions

Frank,

The question here is whether the links you are using contain absolute urls or not. Under the original version of the script, all absolute urls will open in safari. If you want to keep them there, check out my modified plugin at https://github.com/techdude/jQuery.stayInWebApp. I issued a pull request and mrmoses said that it would be incorporated into the main project but it hasn't yet. The main thing is the addition of the way to keep absolute urls in the webapp.

Use should be similar to this:

$(function() {
    var options = {
        selector: "a.stay",
        absToStay: Array("google.com","test.com","cats"), //allow google.com, test.com, and urls containing the word cats to stay.
    };
    $.stayInWebApp(options);
});

Another thing to check if it is not working is to ensure that you are not putting this inside of some other document ready function. It should be on the first scope level, or you should omit the first and last lines.

Hope that helps, ~techdude

techdude avatar Feb 09 '14 14:02 techdude

Frank, UPDATE: I looked over your website, and it looks like most or all of the links are absolute (that is, they include the http://www.pi-gaomovement.com part). In your case specifically, you should use the following:

$(function() {
    var options = {
        selector: "a",
        absToStay: Array("pi-gaomovement.com")
    };
    $.stayInWebApp(options);
});

Or if you are putting it inside of your own document ready function, use this:

$(function() {
    var options = {
        selector: "a",
        absToStay: Array("pi-gaomovement.com")
    };
    $.stayInWebApp(options);
});

Of course, it must be inside of a document ready function because the links must exist in the DOM before they can be modified. Also, this is using the update script available at https://github.com/techdude/jQuery.stayInWebApp, not the original mrmoses script.

Hope this helps you even more, ~techdude

techdude avatar Feb 09 '14 14:02 techdude

Techdude,

Thanks for your help but I must be a complete numbnuts... It's still not working... I'm using your version and dropped the code above into a document ready function but without any luck.

Frank

SonicRevolutions avatar Feb 09 '14 17:02 SonicRevolutions

I think I got some kind of jquery conflict in the page. When I use the exact same code in one of my wordpress pages it works like a charm.

F.

SonicRevolutions avatar Feb 09 '14 20:02 SonicRevolutions

What other scripts are you using? Try replacing the $ with jQuery. This might work for some conflicts. Also, check for script errors in the page when you run in on your computer (use safari inspector).

~techdude

techdude avatar Feb 09 '14 22:02 techdude

Ok, I looked at your source code and you are doing this:


$(document).ready(function() {
$(function() {
    var options = {
        selector: "a",
        absToStay: Array("pi-gaomovement.com")
    };
    $.stayInWebApp(options);
});
});

Instead you should do this:


$(document).ready(function() {
    var options = {
        selector: "a",
        absToStay: Array("pi-gaomovement.com")
    };
    $.stayInWebApp(options);
});

The first option won't run because you are setting the document ready functionality inside of a document ready loop so the event never fires a second time.

Remember, $(function(){}); is just a shortcut for $(document).ready(function(){});

~techdude

techdude avatar Feb 09 '14 22:02 techdude

Thanks again. Still not working, I'm getting a "TypeError: 'undefined' is not a function (evaluating '$.stayInWebApp(options)')" in Safari.

F.

SonicRevolutions avatar Feb 10 '14 21:02 SonicRevolutions

You definitely have a conflict. Use jQuery.stayInWebApp(options); instead of $.stayInWebApp(options);. You need to use jQuery everywhere you use $ because something else on the page is using the $ variable.

~techdude

techdude avatar Feb 11 '14 06:02 techdude

jQuery conflict solved and working as expected! Thanks for your help Techdude!

Frank

SonicRevolutions avatar Feb 12 '14 21:02 SonicRevolutions

Frank,

Glad to hear it is working. I'm pleased I could help.

~techdude

techdude avatar Feb 12 '14 23:02 techdude