Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What am I doing wrong? #6

Open
SonicRevolutions opened this issue Feb 9, 2014 · 10 comments
Open

What am I doing wrong? #6

SonicRevolutions opened this issue Feb 9, 2014 · 10 comments

Comments

@SonicRevolutions
Copy link

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

@techdude
Copy link

techdude commented Feb 9, 2014

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
Copy link

techdude commented Feb 9, 2014

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

@SonicRevolutions
Copy link
Author

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
Copy link
Author

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.

@techdude
Copy link

techdude commented Feb 9, 2014

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
Copy link

techdude commented Feb 9, 2014

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

@SonicRevolutions
Copy link
Author

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

F.

@techdude
Copy link

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

@SonicRevolutions
Copy link
Author

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

Frank

@techdude
Copy link

Frank,

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

~techdude

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants